EUSART_RxTail = 0x00;
EUSART_RxHead = 0x00;
//flush transmit buffer
EUSART_TxTail = 0x00;
EUSART_TxHead = 0x00;
}
I replaced the zeros in the cleaner function for
statements with an “R” and a “T” and called the cleaner
function to produce the hex dump you see in Screenshot 1.
The R characters represent the circular receive buffer while
the T characters block out the circular transmit buffer.
Transmitting Data to the
Dynamixel AX- 12+
Dynamixel AX- 12+ status messages are only returned in
response to the reception of a digital packet originating at
the controlling host. A 128-byte buffer (xmit_buff) is used
to hold the digital packets that are to be transmitted. Some
digital packets contain instructions that require parameters
which are held in a separate 128-byte buffer we call parms.
The elements contained within the xmit_buff and parms
buffers are manipulated with the send_packet function. I’ll
post the send_packet function in its entirety so we can pick
it apart line by line:
volatile char recv_pkt_id,recv_pkt_error,
scratch8;
//***********************************************
//* SEND A DIGITAL PACKET
//***********************************************
void send_packet(char id, char inst,
char parm_len)
{
tx_mode;
xmit_buff[0] = 0xFF;
xmit_buff[1] = 0xFF;
xmit_buff[2] = id;
//+2 = INSTRUCTION+CHECKSUM BYTES
xmit_buff[3] = parm_len + 2;
xmit_buff[4] = inst;
if(parm_len) {
for(index=0; index<parm_len; index++)
{
xmit_buff[index+5] = parms[index];
}
}
send_pkt_chksum = 0;
//+4 = 0xFF+0xFF+ID+LENGTH BYTES
send_pkt_len = xmit_buff[3] + 4;
//-1 = NO CHECKSUM BYTE
for(index=2;index<send_pkt_len-1; index++)
{
//***********************************************
//* PIC18F2620 RAM Definitions
//***********************************************
unsigned int tmsecs1,imsecs1,tsecs1;
char isecs1;
char parms[128];
char xmit_buff[128];
char recv_buff[128];
volatile char index,send_pkt_chksum,
recv_pkt_chksum,recv_pkt_start;
volatile char calc_chk,recv_pkt_len,
send_pkt_len,rc;
send_pkt_chksum += xmit_buff[index];
}
//NOT the computed checksum
xmit_buff[index] = ~send_pkt_chksum;
//SEND ALL BYTES
for(index=0;index<send_pkt_len; index++)
{
sendchar(xmit_buff[index]);
}
rx_mode;
}
The send_packet function requires
three function parameters: the destination
robot actuator ID, the instruction to be
transmitted, and the number of instruction
parameters encapsulated within the digital
packet. When called, the send_packet
function places the half-duplex link in
transmit mode and begins to assemble the
digital packet in the xmit_buff array. The
sync bytes are loaded into the first two
positions of the transmit buffer, followed
by the destination robot actuator ID byte.
The third transmit buffer slot is occupied
by the LENGTH byte, which is the total of
SCREENSHOT 1. This is a capture of the File
Registers window of the MPLAB IDE. You
can easily visualize the 128-byte circular
receive and transmit buffer memory areas.
34 SERVO 05.2009