Pololu Robotics & Electronics
My account Comments or questions? About Pololu Contact Ordering information Distributors

Jrk 21v3 communication problem



I am pretty new to MCU programming and using the Jrk 21v3 motor controller. I am using a HCS12 microcotrolller from freescale to send/receive messages to/from the Jrk 21v3 via a Serial Control Interface. I have the microcontroller setup to format the messages in UART 8N1; 1 low start bit, data bits 0 to 6, and a high stop bit. I am trying to setup a network with a RoboClaw motor controller and the Jrk. To do this I think I need to use the Pololu protocol.

I have been able to send commands in the compact protocol to get the Jrk to move a linear actuator to a target position, but when I try to use the Pololu protocol I get an error on the Jrk. I am sending 0xAA as the first byte, the device of the Jrk (11 or 0x0B) as the second byte, the set target command (0x40) with the lower 5 bits of the target value in the third byte, and the upper 7 bits of the target value in the fourth byte. I am not getting an error on the Jrk, but it is not moving the linear actuator either.

Here is the code I am using to send the bytes, the (!(SCI0SR1 & 0x80) is a flag that is raised when there is a byte to transmit. The byte it transmitted bitwise so this flag is lowered after the transmission is complete. SCI0DRL is the register that the bytes are written or read from.

[code]void jrkSetTarget (unsigned int s) {

while (SCI0SR1_TDRE) 
  SCI0DRL = 0xAA;             // send to set baud rate and initialize communications

while (SCI0SR1_TDRE) 
  SCI0DRL = 0x0B;            // send the device number

while(SCI0SR1_TDRE)       // make sure the last bit is gone
  SCI0DRL = 0x40 + (s & 0x1F);	// send target command and lower 5 bits of target position

while(SCI0SR1_TDRE)       // make sure the last bit is gone
  SCI0DRL = ((s & 0xFE0) >> 5);		 // send the upper 7 bits of the target position

delays (10);                           // just gives a little time for the linear actuator to get to the target position


I should also mention that I know the bits are being sent because I am watching them on my oscilloscope


I found the problem in my code, as usual it was something silly. I needed ; after the while loops. Not sure why I didn’t get a compile error, but the motor controller is now working when I send commands to move.

I am still having a problem receiving messages from the Jrk motor controller. When the request is sent I can see a response on my oscilloscope, but am unable to receive the response. Can someone tell me the format that the response will be in? For example, I am asking the Jrk for the scaled target value (0xA7) here:

void getFeedBack (void) {
int a = 0xA7, c, x;

while(!(SCI0SR1 & 0x80)); // make sure the last bit is gone
SCI0DRL = 0xAA; // send baud rate initialization
while(!(SCI0SR1 & 0x80)); // make sure the last bit is gone
SCI0DRL = 0x0B; // send device name/number
while(!(SCI0SR1 & 0x80)); // make sure the last bit is gone
SCI0DRL = (a & 0x7F); // send command code for scaled feedback with MSB cleared

while (SCI0SR1 & 0x20); // wait for the last bit
c = SCI0DRL; // save response from the motor controller
while (SCI0SR1 & 0x20); // wait for the last bit
x = SCI0DRL; // save response from motor controller

I think this is a 2 byte response with the lower byte sent first, then the upper. Lets say the scaled target value is 4000. The lower byte should be 0xA0 and the upper byte should be 0x0F; is this correct? Is the response in the UART 8N1 format with a start bit, data, stop bit?



It sounds like your understanding is correct. When you use one of the jrk’s variable reading serial commands with the “Two bytes” read variable command byte, you should receive the least significant byte followed by the most significant byte. It looks like you might have made a typo when you referred to “scaled target”. If you meant scaled feedback, then your example of receiving 0xA0 and 0x0F for a value of 4000 is correct. The data format should be 8 databits, one stop bit, with no parity bit (i.e. 8-N-1).