yadunandankasu yadunandankasu

msCAN problem with MC9S12XS128

Discussion created by yadunandankasu yadunandankasu on Mar 14, 2009
Latest reply on Mar 25, 2009 by yadunandankasu yadunandankasu

Dear every one, I'm working with mc9s12xs128 MCU. I'm just trying to implement the basic CAN communication between my computer and my target board . But I couldn't do it successfully. I just did the following the things in my simple projetct.


1. Initialize the msCAN module.

2. Enable the CAN Rx interrupt.

3. Implemented the ISR for the CAN Rx interrupt.


But, after I download the code to the MCU throuh a usb type P&E cable and run it and when I send a CAN message using CAN king or CANoe, the Rx interrupt is never reached. The RSTAT[1:0] register value shows as a binary value of '10' that means,Rx error counter > 127. Can anyone plz help me out from this situation. Below shown are my project details...



Project                : Basic CAN comm. between a PC and a CAN node 

Target Board with :  mc9s12xs128 MCU with 8Mhz osc clock

MCU                   :  mc9s12xs128

Compiler              :  Codwarrior v.5.7.0


unsigned char RxInterruptSucess;
unsigned char RxD_Buf[8];
void Init_CAN(void){  CAN0CTL0 = 0x01;  while ((CAN0CTL1 & 0x01) != 0x01);  CAN0CTL1 = 0x80;  /* CAN module Enabled, Oscclk = 8MHz */  CAN0BTR0 = 0x01;  /* SJW = 1Tq clock cycles, Prescale 2 */  CAN0BTR1 = 0x14;  /* 1 sample per bit,Segment2 = 2Tq, Segment1 = 5Tq */  CAN0IDAC = 0x10   /* 4 16bit acceptance fileters */     CAN0IDMR0 = 0xFF;   CAN0IDMR1 = 0xFF;   CAN0IDMR2 = 0xFF;   CAN0IDMR3 = 0xFF;   CAN0IDMR4 = 0xFF;   CAN0IDMR5 = 0xFF;    CAN0IDMR6 = 0xFF;   CAN0IDMR7 = 0xFF;   CAN0CTL0 &= 0xFE; /* Normal Operation Request */  while ((CAN0CTL1 & 0x01) == 0x01); /* wait til node enters normal                                         mode*/ }void main(void){  CAN_Init();  EnableInterrupts;  while(CAN0CTL0_SYNCH == 0) /* wait til node synchronize to bus */  {    ;  }  CAN0RIER_RXFIE = 1;   /* enable Rx interrupt */  for(;;) {}}#pragma CODE_SEG NON_BANKEDinterrupt void _CAN_Rx_Interrupt(void){  byte i;  for(i=0; i<8; i++)  {    RxD_Buf[i] = *((byte *)&CAN0RXDSR0 + i); /* save received data */  }   CAN0CTL0|=0x80;  /* clear the received frame flag */                 CAN0RFLG|=0x01;  /* clear the RXF flag to release the buffer */  RxInterruptSucess = 1;   }#pragma CODE_SEG DEFAULT
And I updated the vector in the .prm file as belowVECTOR ADDRESS 0xFFB2 _CAN_Rx_Interrupt



I could not able to find the reason, the time when I send any message to the target, the RSTAT[1:0] immediately goes to the binary value of '10' and Rx interrupt is never occuring. I can see a continuous error frames on CANking or CANoe.


Kindly help me to find out the solution.


Thanks & Regards