SCI not working completely

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

SCI not working completely

621 Views
thms_rw
Contributor I

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);                

}

Labels (1)
0 Kudos
2 Replies

345 Views
lama
NXP TechSupport
NXP TechSupport
  • - SCI_init(): could you please check your setup:

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

0x29 or 29 hexadecimal or decimal? there is no info about used MCU to be sure the formula is OK and BUSCLK so full review is not possible.

  • - I do not understand why you send data again in the get feedback function..

I will suppose 8MHz BUSCLK in following example. Moreover, the example supposes the data from responder are not sent sooner than everything is sent from sender. othervise receive overflow can happen. In such a case you should use receive interrupt to be able to receive data anytime they are received.

void SCI0_init(void)

{

//........................................

  // SCI0

  // BR = BUSCLK / (16*Baud rate)

  // SCICR1: Loops sciswai rsrc   m    wake ilt   pe    pt

  // 0-LOOPS=RSRC=0 => 1 Single-wire mode with Rx input connected to TXD

  // 1-SCI dis. in wait mode                            

  // 0-if RSRC=1-RxTx intern. connected if loops=1

  // 0-start+8 data+1 stop bit                        

  // 0-IDLE mark wake up                                

  // 1-idle char. bit count begins after stop bit       

  // 0-parity fction disabled                           

  // 0-odd parity                                     

  // SCICR2: tie   tcie rie  ilie   te re   rwu   sbk

  // 0-Tx empty intr disabled                           

  // 0-Tx complete intr disabled                        

  // 0-Rx full + OverRun interrupts

  // 0-idle line intr disabled                          

  // 1-transmitter enabled

  // 1-receiver enabled

  // 0-receiver normal operation

  // 0-no break characters

//........................................

SCI0BD  = 0x34 ; //9600Bd at 8MHz BUSCLK

SCI0CR1 = 0x44;

SCI0CR2 = 0x0C;

}

void send_data(void)

{

while(!SCI0SR1_TC); // wait while data is not sent; the same as while(!(SCI0SR1&0x40));

    // or  while(!SCI0SR1_TDRE);    // wait while Tx buffer is not empty; the same as while(!(SCI0SR1&0x80));

     SCI0DRL = sci0_data1_out;

while(!SCI0SR1_TC); // wait till previous data is being sent

     SCI0DRL = sci0_data2_out;

while(!SCI0SR1_TC); // wait till previous data is being sent

     SCI0DRL = sci0_data3_out;

while(!SCI0SR1_TC); // wait till previous data is being sent

     SCI0DRL = sci0_data4_out;

}

void get_data_SCI0(void)

{

while(!(SCI0SR1_TC));             // wait while data not received; the same as while(!(SCI0SR1 & 0x20));

sci0_data1_in =  SCI0DRL;     // get data

while(!(SCI0SR1_TC));             // wait while data not received; the same as while(!(SCI0SR1 & 0x20));

sci0_data2_in =  SCI0DRL;    // get data

while(!(SCI0SR1_TC));             // wait while data not received; the same as while(!(SCI0SR1 & 0x20));

sci0_data3_in =  SCI0DRL;   // get data

}

Best Regards, Ladislav

0 Kudos

345 Views
iggi
NXP Employee
NXP Employee

Hi,

what exact HCS12 part do you use? It would be good to know the part number. This can help determine the maskset, just to check if there are possible errata.

Did you try connecting the MCU with PC hyperterminal? This is good to test if the communication works OK, to ensure MCU side is works correctly. For example, the echo from the terminal.

0 Kudos