AnsweredAssumed Answered

S12XEP100 MSCAN loopback not working?

Question asked by Szymon Mroczek on Oct 9, 2010
Latest reply on Nov 1, 2010 by Szymon Mroczek

Hi All,

 

So far I have never used loopback mode. Never needed it.

Until today.

I prepare and schedule CAN message for transmission.

Then I wait for CAN0RFLG register's RXF flag with no success. :smileysad:

 

Couldn't find the solution for half a day. Read documentation several times, tried all options which came to my mind, search that forum... No success.

Checked DEMO9S12XEP100 documentation... The CAN jumpers are OK.

I was able to receive CAN message from remote node (usb PCAN interface and PCAN View application).

I was not able to send any message (that's probably for another topic) so switched to loopback mode...

 

Please, have a look at the main routine below. Thanks!

 

 

void main(void) {

  byte canbuffs=0;
  word received_id=0;
 
  DisableInterrupts;

  /* CAN tests: */
 
  /* request CAN initialisation mode */
  _CAN0CTL0.Bits.INITRQ = 1;
 
  /* wait for initialisation acknowledge */
  while(_CAN0CTL1.Bits.INITAK == 0) {
  }
 
  /* enable CAN module */
  _CAN0CTL1.Bits.CANE = 1;
 
  /* CAN clock source is OSC clock: 4MHz */
  _CAN0CTL1.Bits.CLKsrc=0;
 
  /* enable loopback mode */
  _CAN0CTL1.Bits.LOOPB = 1;
 
  /* disable acceptance filters by setting acceptance masks */
  _CAN0IDMR0.Byte = 0xFF;
  _CAN0IDMR1.Byte = 0xFF;
  _CAN0IDMR2.Byte = 0xFF;
  _CAN0IDMR3.Byte = 0xFF;
  _CAN0IDMR4.Byte = 0xFF;
  _CAN0IDMR5.Byte = 0xFF;
  _CAN0IDMR6.Byte = 0xFF;
  _CAN0IDMR7.Byte = 0xFF;
 
  /* configure baud rate: 125kbps for 4MHz OSC clock source */
  _CAN0BTR0.MergedBits.grpBRP = 1;      /* prescaler value 2 */
  _CAN0BTR0.MergedBits.grpSJW = 0;      /* synchronisation jump width 1 Tq */
  _CAN0BTR1.MergedBits.grpTSEG_10 = 7;  /* time segment1 8 Tq */
  _CAN0BTR1.MergedBits.grpTSEG_20 = 6;  /* time segment2 7 Tq */
  _CAN0BTR1.Bits.SAMP = 0;              /* one sample per bit */
 
  /* leave initialisation mode */
  _CAN0CTL0.Bits.INITRQ = 0;
 
  /* wait to enter normal mode */
  while(_CAN0CTL1.Bits.INITAK == 1) {
  }
 
  /* disable receive / transmit interrupts */
  _CAN0RIER.Byte = 0x00;
  _CAN0TIER.Byte = 0x00;
 
  /* wait for CAN module synchronisation */
  while(_CAN0CTL0.Bits.SYNCH == 0) {
  }
 
  /* set module to wake up from sleep if there is CAN activity */
  _CAN0CTL0.Bits.WUPE = 1;                
 
 
 
  /* clear receive buffer full flag to release the buffer */
  /* just in case although no messages has been received yet  */
  /* does not make any difference if the line is removed */
  _CAN0RFLG.Bits.RXF = 0;
 
  /* CAN transmit tests: */
  /* loop-back mode */
 
  /* select empty transmit buffer */
   _CAN0TBSEL.Byte = _CAN0TFLG.Byte;
 
  /* fill selected transmit buffer */         
  /* with some example data */
  /* CAN Node Id: 0x7F0 */
  /* Data: 0x11 0x12 0x13 ... 0x18 */
  /* Length: 8 bytes */
  _CAN0TXIDR0.Byte = (byte)(0x7F0>>3);
  _CAN0TXIDR1.Byte = (byte)(0x7F0<<5);
 
  _CAN0TXDSR0.Byte = 0x11;
  _CAN0TXDSR1.Byte = 0x12;
  _CAN0TXDSR2.Byte = 0x13;
  _CAN0TXDSR3.Byte = 0x14;
  _CAN0TXDSR4.Byte = 0x15;
  _CAN0TXDSR5.Byte = 0x16;
  _CAN0TXDSR6.Byte = 0x17;
  _CAN0TXDSR7.Byte = 0x18;
 
  _CAN0TXDLR.Byte = 8;
 
  /* schedule transmit buffer for transmission */
  _CAN0TFLG.Byte = ~_CAN0TBSEL.Byte; // ??
 
 
  /* wait for new message in receive buffer */
  /* stops on this line, does not go any further */
  while (_CAN0RFLG.Bits.RXF == 0) {
  }
 
  /* ID received */
  received_id = (_CAN0RXIDR0.Byte);
  received_id <<= 3;
  received_id |= (_CAN0RXIDR1.Byte >> 5);

  /* clear receive buffer full flag */
  _CAN0RFLG.Bits.RXF = 0;
 
 
  /* CAN tests completed */


Any ideas what's wrong with it?

Outcomes