Oddly behaving SCI GT16A

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

Oddly behaving SCI GT16A

461 Views
woohoo
Contributor I

Hi

 

At the moment my SCI is only receiving certain characters and I can't figure out why. For example when I send '1' the debugger shows that the micro receiver 0xb1. I have gone through the code and am hoping that someone else has had this happen before and can help.

 

The code:

#include <hidef.h>      // For EnableInterrupts macro#include "derivative.h" // Include peripheral declarations//****** Initialising Functions *******void SCI_initialise (void);void CLK_Initialise (void);//******* Interrupt Functions *********void SCI_interrupt (void);        //********** Motor Variables ********** volatile int PacketReceiveIndex = 0;char PacketReceive[4];volatile int DataReceived = 0;//*********** Main Routine ************void main(void) {  SOPT  = 0x53;     // Disable Computer Operating Properly (COP) watchdog    CLK_Initialise ();  SCI_initialise();      asm ("CLI");      // Enable Interrupts      for(;;) {        if (DataReceived == 1) {                         DataReceived = 0;       // reset           }   }}//-------------------------------------------------------------------void CLK_Initialise (void){    ICGC2 = 0x70;             // Sets MFD divider  ICGC1 = 0x38;             // 32kHz -> 18.874368MHz bus rate  while (ICGS1_LOCK==0);    // Loop until PLL locks}        //-------------------------------------------------------------------interrupt 20// Always receive 4 bytesvoid SCI_interrupt (void) {  unsigned char ackn;    ackn = SCI2S1;                  //Acknowledge the interrupt    PacketReceive[PacketReceiveIndex] = SCI2D; // Read the incoming data  PacketReceiveIndex++;           // Increment the counter    if (PacketReceiveIndex == 4 ) {    PacketReceiveIndex = 0;       // Reset to allow for new data to come in    DataReceived = 1;             // Indicate the data has been received  }  }//--------------------------------------------------------------------void SCI_initialise (void) {  SCI2BDH = 0x00;   // Serial baud rate divider  SCI2BDL = 123;    // Serial baud rate divisor for 9600 (122.88)  //SCI2BDL = 61;     // Serial baud rate divisor for 19200 (61.44)  //SCI2BDL = 10;     // Serial baud rate divisor for 115200 (10.24)  SCI2C1  = 0x00;   // Serial register 1 setup  SCI2C2  = 0x2C;   // Serial register 2 setup    /* SCI2C2 setup: TIE   = 0 transmitter interrupt          - disabled                   TCIE  = 0 transmission complete interrupt- disabled                   RIE   = 1 receive interrupt              - enabled                   ILIE  = 0 idle line interrupt            - disabled                   TE    = 1 transmitter                    - enabled                   RE    = 1 receiver                       - enabled                   RWU   = 0 receiver wake up               - disabled                   SBK   = 0 send break bit                 - disabled  */}//--------------------------------------------------------------------

 Thanks

Labels (1)
0 Kudos
Reply
1 Reply

303 Views
bigmac
Specialist III

Hello,

 

It is possible that, whatever you are using to generate the ASCI data is sending seven data bits, plus a parity bit, in this case even parity.  If this theory is correct, the numerals '0', '3', '5', '6' and '9' should be correctly received.

 

I would consider that the baud rate error at 115200 bits per second may be somewhat on the high side for some applications.  Other choices of ICG multiplier value, while producing a lower bus frequency, can produce significantly better baud rate accuracy.  Compare results with a bus frequency of 14.68 MHz (MFD setting to give N = 14).

 

Other crystal frequencies are capable of producing exact baud rates, by generating a bus frequency of 14.7456MHz.  Commonly available crystal frequencies would be 2.4576, 3.3864 or 4.9152 MHz.

 

Also note that the SCI receive ISR must occupy less than SCIBD * 10 cycles, to prevent over-run by the next character.  This may well prove impossible with a maximum limit less than 80-100 cycles available, with a baud rate of 115200 bits per second.

 

Regards,

Mac

 

0 Kudos
Reply