cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 Discovery program for moving Dynamixel

itsna_azz
Associate II
Posted on August 05, 2015 at 08:11

Hello, I am a college student and a beginner programmer, I got a project to make a library using STM32F4 Discovery to move a Dynamixel motor type XL-320. I already studied the basic communication for commanding Dynamixel XL-320 (http://support.robotis.com/en/product/dynamixel_pro/communication/instruction_status_packet.htm) and I already made some of the program list, but it doesn't work, can somebody help me? Thank you very much.

I use some of the program from HelloSpoon, to get the CRC value (https://github.com/HelloSpoon/HelloSpoon-Spark/blob/master/firmware/dxl_pro.cpp)

Here is some of the program list I made :

void Dyna_move(unsigned char ID, int Position)

{

    //length

    XL_LENGTH_L = L_Byte(XL_GOAL_P_LENGTH);

    XL_LENGTH_H = H_Byte(XL_GOAL_P_LENGTH);

    Packet_Length = XL_GOAL_P_LENGTH;

    //address

    XL_ADDRESS_L = L_Byte(XL_GOAL_POSITION);

    XL_ADDRESS_H = H_Byte(XL_GOAL_POSITION);

    //position

    POS_L = L_Byte(Position);

    POS_H = H_Byte(Position);

    //txpacket

    unsigned char DataSend[] = { XL_START1,

                                 XL_START1,

                                 XL_START2,

                                 XL_RESERVED,

                                 ID,

                                 XL_LENGTH_L,

                                 XL_LENGTH_H,

                                 XL_WRITE_DATA,

                                 XL_ADDRESS_L,

                                 XL_ADDRESS_H,

                                 POS_L,

                                 POS_H,

                                 CRC_L,

                                 CRC_H };

    for(count=0;count<(XL_GOAL_P_LENGTH+7);count++)

    {

    TxPacket[count]=DataSend[count];

    }

    //CRC

    CRC_X = update_crc (CRC_ACCUM, TxPacket , (5+Packet_Length) ) ;

    CRC_L = L_Byte(CRC_X);

    CRC_H = H_Byte(CRC_X);

    UART_SendByte(DYNAMIXEL, XL_START1);

    UART_SendByte(DYNAMIXEL, XL_START1);

    UART_SendByte(DYNAMIXEL, XL_START2);

    UART_SendByte(DYNAMIXEL, XL_RESERVED);

    UART_SendByte(DYNAMIXEL, ID);

    UART_SendByte(DYNAMIXEL, XL_LENGTH_L);

    UART_SendByte(DYNAMIXEL, XL_LENGTH_H);

    UART_SendByte(DYNAMIXEL, XL_WRITE_DATA);

    UART_SendByte(DYNAMIXEL, XL_ADDRESS_L);

    UART_SendByte(DYNAMIXEL, XL_ADDRESS_H);

    UART_SendByte(DYNAMIXEL, POS_L);

    UART_SendByte(DYNAMIXEL, POS_H);

    UART_SendByte(DYNAMIXEL, CRC_L);

    UART_SendByte(DYNAMIXEL, CRC_H);

    Delayus(100);

}

#stm32 #stm32f4 #discovery #usart
2 REPLIES 2
Posted on August 05, 2015 at 14:06

Does the UART_SendByte() wait for TXE to assert before sending each data byte?

Perhaps you can provide a number of example packets that you are sending? ie the stream of hex bytes. The code you provided doesn't really make it easy to do remotely.

I'd suggest to write equivalent code you can run on a PC that just computes and prints packets, and make sure that's valid. Look if there are example packets provided for the motor documentation which would allow you to cross check the values computed by your code.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
itsna_azz
Associate II
Posted on August 06, 2015 at 07:53

Yes, it waits for TXE, here's the list program

void UART_SendByte(UART_NAME_t uart, uint16_t wert)

{

  // was waiting until old byte sent

  while (USART_GetFlagStatus(UART[uart].UART, USART_FLAG_TXE) == RESET);

  USART_SendData(UART[uart].UART, wert);

}

The data I sent is like this, it consists ID of the dynamixel (0x01) and the position we want for the dynamixel (0x3FF)

0xFF 0xFF 0xFD 0x00 0x01 0x07 0x00 0x03 0x30 0x00 0xFF 0x03 CRC_L CRC_H

What I already did to check the packet is using a USB to TTL and connecting it to the STM32F4 I am using, and I see it in the computer using Parallax program, but what I receive is some symbol I did not know, like this

ÿ, sometimes it appeared twice, or three times or once then vanished, and reappeared again in a quick pace. But sometimes the symbols change when I change the parameter like ID or position. There was even a time when I sent a data, it didn't match with the ASCII table. I am confused, Sir, maybe there is something wrong in the way I did it? Can you give me some advice?