2 Replies Latest reply on Nov 21, 2015 6:56 PM by flux2002

    UART BYTE Datatype @ 1Mbps - Dynamix Servo

    flux2002

      Overview: Recently purchased a Dynamixel AX-12W servo and attempting to build custom library since not able to find for Edison.  These servos require a half-duplex UART connection at 1Mbps and plan to use tri-state buffers (FairSemi 74F244) and GPIO control to convert half-duplex from servo to full-duplex into Edison.  This will allow both instructions to be sent and status to be returned using a single wire.

      Note: I have already confirmed on oscilloscope that I can transmit char at 1Mbps with no issue (8bit, no parity, 1stop).

       

      Problem: The servos expect bytes to be sent instead of char.   Pseudo code below to show simple instruction packet.

      LINE 1 DIRECTION_PORT = TX_DIRECTION   //Set tri-state buffer to High-Z for Rx, and enable Tx.

      LINE 2 TxDByte(0xff);   //Notifies beginning of packet - part 1

      LINE 3 TxDByte(0xff);   //Notifies beginning of packet - part 2

      LINE 4 TxDByte(bID);  //ID of the servo to be addressed

      LINE 5 TxDByte(bLength); //length is calculated as “the number of Parameters (N) + 2

      LINE 6 TxDByte(bInstruction);  //instruction ID

      LINE 7 TxDByte(Parameter0); TxDByte(Parameter1);

       

      Question:  Is there a way to use mraa_uart_write(uart, buffer, sizeof(buffer)) definition or other mechanism to send bytes instead of char?


      Suggestion: I was thinking about reverse engineering the char ASCII table to create a mapping to get the byte definitions I needed, but this would be quite ugly and not sure possible as 0xFF undefined and needed to notify beginning of packet.

       

      Dynamix Reference:

      TechSupport_ENG

      Overview of Communication

        • 1. Re: UART BYTE Datatype @ 1Mbps - Dynamix Servo
          MiguelAngelLV

          A char and a byte are the same.

           

          You can use char as bytes without problems.

           

          char data = 0x01
          
          • 2. Re: UART BYTE Datatype @ 1Mbps - Dynamix Servo
            flux2002

            Thanks Miguel this worked. For anyone trying to use Dynamix with Edison here is some reference code for transmitting command.

             

            mraa_gpio_write(mstrPin_TX, 1);   //set transmit for half-duplex to full-duplex converter logic

            mraa_gpio_write(mstrPin_RX, 0);

             

            char packet_start1[1] = {'\xFF'};

            char packet_start2[1] = {'\xFF'};

             

            mraa_uart_write(mstrComm_UART, packet_start1, sizeof(packet_start1));

            mraa_uart_write(mstrComm_UART, packet_start2, sizeof(packet_start2));

            mraa_uart_write(mstrComm_UART, _command.ID, sizeof(_command.ID));                                        

            mraa_uart_write(mstrComm_UART, _command.Length, sizeof(_command.Length));

            mraa_uart_write(mstrComm_UART, _command.Instruction, sizeof(_command.Instruction));

            mraa_uart_write(mstrComm_UART, _command.Param_Address, sizeof(_command.Param_Address));

             

            char data_packet[1];

            for (int i = 0; i < _command.Count_Param_Data; i++) {

                data_packet[0] = _command.Param_Data[i];

                mraa_uart_write(mstrComm_UART, data_packet, sizeof(data_packet));

            }

            mraa_uart_write(mstrComm_UART, _command.Check_Sum, sizeof(_command.Check_Sum));

             

            mraa_gpio_write(mstrPin_TX, 0);  //set receive for half-duplex to full-duplex converter logic

            mraa_gpio_write(mstrPin_RX, 1);