AnsweredAssumed Answered

SPC5606BK Receiving all CAN IDs

Question asked by H S on Sep 27, 2016
Latest reply on Sep 27, 2016 by Petr Stancik

HI,Dear:

I am trying to receive all possible (standard) CAN IDs with one FlexCAN module on SPC5606BK.

 

At the moment, I am using the following code, that only works for receiving messages with only one single CAN ID。 Is it possible to receive all CAN IDs on one message buffer? Is there any example code for receiving any CAN messages with all CAN IDs?

 

Thank you very much!

 

 

void InitCAN_1 (void)

{

uint8_t   i;

CAN_1.MCR.R = 0x5000023F;       /* Put in Freeze Mode & enable all 64 msg bufs */

CAN_1.CR.R = 0x00DB0006;        /* Configure for 8MHz OSC, 100KHz bit time */

for (i=0; i<64; i++)

{

CAN_1.BUF[i].CS.B.CODE = 0;   /* Inactivate all message buffers */

}  

CAN_1.BUF[4].CS.B.IDE = 1;      /* MB 4 will look for a standard ID */ /*IDE=0表示Frame format(帧格式) is standard*/

CAN_1.BUF[4].ID.R = 0x18005602; /* MB 4 will look for ID = 555 */ /*ID(帧标识符)*/ //扩展帧

 

CAN_1.BUF[4].CS.B.CODE = 4;     /* MB 4 set to RX EMPTY */

CAN_1.RXGMASK.R = 0x1FFFFFFF;   /* Global acceptance mask */

SIU.PSMI[0].R = 0x01;           /* MPC56xxB: Select PCR 35 for CAN1RX Input */

CAN_1.MCR.R = 0x0000003F;       /* Negate FlexCAN 1 halt state for  64 MB */

}

 

void RecieveMsg1 (void)

{

uint8_t j;

vuint32_t dummy;

//while (CAN_1.IFRL.B.BUF04I == 0) {}; /* Wait for CAN 1 MB 4 flag */

if(CAN_1.IFRL.B.BUF04I == 1)

{

RxCODE = CAN_1.BUF[4].CS.B.CODE; /* Read CODE, ID, LENGTH, DATA, TIMESTAMP */

RxID = CAN_1.BUF[4].ID.R;

 

RxLENGTH = CAN_1.BUF[4].CS.B.LENGTH;

for (j=0; j<RxLENGTH; j++)

{

RxDATA[j] = CAN_1.BUF[4].DATA.B[j];

 

}

RxTIMESTAMP = CAN_1.BUF[4].CS.B.TIMESTAMP;

dummy = CAN_1.TIMER.R; /* Read TIMER to unlock message buffers */

CAN_1.IFRL.R = 0x00000010; /* Clear CAN 1 MB 4 flag */

}

 

}

Outcomes