SPC5606BK Receiving all CAN IDs

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

SPC5606BK Receiving all CAN IDs

885 Views
458362783
Contributor I

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 */

}

 

}

Labels (1)
0 Kudos
Reply
1 Reply

701 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

You can just set a mask acceptance register(s) properly, means clear all bits. In that case the received ID is “don’t care”. If you want to receive both standard and extended frames then at least 2 MBs should be set for receive, one for standard (IDE=0) and other for extended frames (IDE=1).

So try to clear CAN_1.RXGMASK.R in your config.

BR, Petr

0 Kudos
Reply