AnsweredAssumed Answered

SCI not working completely

Question asked by Tom R on Feb 7, 2015
Latest reply on Mar 3, 2015 by lama

Hello,

 

I am a rookie so, please speak in layman's terms and I will do my best to keep up. I am trying to create a small SCI network to send/receive messages to/from two motor controllers. The network consists of the HCS12, a Pololu Jrk 21v3 motor controller, and a Orion robotics RoboClaw 2x30 motor controller. I am only planning on using SCI0, so I have the Tx and Rx connected to pins PS0 and PS1. Presently, I can send commands to the motor controllers and they respond as predicted, however I am not able to receive replies from them at this point. I am using the integrated potentiometer on the MCU board to determine the command data value that I am sending, speed and direction in one case, and a target position in the other. At the moment, I am only trying to make sure the communication is formatted correctly before I move on to error handling, using interrupts to send commands, and some other control features, so the code I will post is incomplete. I have my oscilloscope connected to the Tx and Rx pins to see the signal. I can see the Tx  going and what I think is a response from the motor controller on the Rx. but that Rx value does not seem to be getting assigned to my variable.  Here is the snippet of code that I am using for initialization of the SCI registers, to send movement commands, and receive replies on the Rx pin. The bold underlined part is what does not seem to be working. Thanks in advance for any help or suggestions.

 

void init_SCI () {

 

  SCI0BDH = 0x00;            

  SCI0BDL = 0x29;             // baud rate at 9572 bps = bus clk / (16 * 29)

  SCI0CR1 = 0x00;             // UART configuration: 8 data bits, No parity bit, 1 stop bit

  SCI0CR2 = 0x2C;             // Enable Tx, Rx, enable the receive register full flag

}

 

void jrkSetTarget (unsigned int s) {

 

  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 = 0x40 + (s & 0x1F);  // set target command and lower 5 bits of the target value

  while(!(SCI0SR1 & 0x80));         // make sure the last bit is gone

        SCI0DRL = (s >> 5) & 0x7F;  // send remaining 7 bits of the target value

       

    delay2m ();                     // kill some time while the linear actuator moves   

    delay2m ();   

    delay2m ();   

    delay2m ();   

    delay2m ();

    getFeedBack ();

}

 

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 & 0x1F);         // send command code for scaled feedback

//  while(!(SCI0SR1 & 0x80));       

//    SCI0DRL = (a >> 5) & 0x7F;

       

  while (SCI0SR1 & 0x20);          // wait for the last bit

    c = SCI0DRL;                // get response from the motor controller

  while (SCI0SR1 & 0x20);          // wait for the last bit

    x = SCI0DRL;                // get response from motor controller

//  while (SCI0SR1_RDRF);          // wait for the last bit

//    x = SCI0DRL;

   

  lcdPosition(2,0);               // lcd position

  lcdPuts ("Error: ");            // Put "Error: " on the lcd

  lcdPosition (2,7);

  lcdPutch (c);                

}

Outcomes