Oliver Hobson

Oddly behaving SCI GT16A

Discussion created by Oliver Hobson on May 3, 2012
Latest reply on May 3, 2012 by bigmac

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

Outcomes