how to use Can_SetFilter by mailbox

cancel
Showing results for 
Search instead for 
Did you mean: 

how to use Can_SetFilter by mailbox

313 Views
Contributor II

Hi, now I develop CAN module based on S32R274 FLEXCAN and I have met a problem,

 I set CAN payload to 64 byte and CAN Rx configured as interrupt,not FIFO.

I set mailbox4 to receive CANID 0x002 ,

mailbox5 to receive CANID 0x203/0x213(mask 0xFFFFFFEF),

mailbox6 to receive 0x215.

when I init mailbox5, I call Can_SetFilter with mask 0xFFFFFFEF

And I print the mailbox index when I receiving 0x002/0x203/0x213/0x215,

I received 0x002 first ,then received 0x203/0x213/0x215 in order, I found the mailbox is 4-4-4-4,not 4-5-5-6

I don't know why,can you help me to understand?

Is the way I use the api-Can_SetFlter wrong?

Tags (2)
4 Replies

117 Views
NXP TechSupport
NXP TechSupport

Hi,

what is the API/driver you use in fact?

generally for the setting, regardless of API...

If individual mask registers are used (MCR[IMRQ]=1) what is the setting of RXIMR registers corresponding to other MBs?

Also I would suggest to check programmed value of MBs and mask registers after init is done. 

MB offsets differs based on payload configured, so be sure right addresses are written. Chapter 53.4.36 FlexCAN message buffer memory map of the RM gives a summary.

BR, Petr

0 Kudos

117 Views
Contributor II

Dear Petr,

Thanks for your reply.Let's start with my needs.

I need use CANFD with payload 64,so there are only seven mailboxes at most,

I need transmit 4 messages with individual mailbox(MB0-MB3),and receive 4 messages  saved in MB5-7(so I need CAN mask).

Here's how I use can_pal module  API during initialization

1.CAN_Init

2.CAN_InstallEventCallback(CAN2_instance,CAN2_Rx_IRQ,NULL)

3.CAN_CfgRxBuff: MB4/5/6 config as Rx mb

   MB   CAN-ID

   4         0x002

   5         0x203

   6         0x215 

4.CAN_SetFilter:

   MB   MASK

   4         have not call CAN_SetFilter

   5         0x7EF( to receive 0x203/0x213)

   6        have not call CAN_SetFilter

5.CAN_Receive to wait next CAN Rx interrupt

6.CAN_CfgTxBuff:MB0/1/2/3 config as Tx mb

When CAN_RX interrupt occurs,in function CAN2_Rx_IRQ(refer to above step2 ,install eventcallback) I do this below,

1.print MB index;

2.CAN_CfgRxBuff: according to current index( index_number always to 4/5/6)

   MB   CAN-ID

   4         0x002

   5         0x203

   6         0x215 

3.CAN_SetFilter::according to current index( index_number always to 4/5/6)

   MB   MASK

   4         have not call CAN_SetFilter

   5         0x7EF( to receive 0x203/0x213)

   6        have not call CAN_SetFilter

4.CAN_Receive to wait next CAN Rx interrupt

I use CANoe transmit 4 CAN messages for verify my software,0x002/0x203/0x213/0x215 in order,

I found the print Log information shows that rx mailbox  index is 4-4-4-4,not 4-5-5-6.

Is the way I call these API from can_pal wrong?

Or these API should be called by special sequence?

0 Kudos

117 Views
NXP TechSupport
NXP TechSupport

Hi,

can_pal driver clears individual masking registers (RXIMR) during Init and when CAN_SetRxFilter is called it uses individual masking scheme. Thus masking filter has to be set to all RX MBs used otherwise cleared RXIMR caused ID to be don't care, so you can easily receive all into the first RX MB. Which you have in fact.

So not sure what ID type you have but you should call this...

for ID_STD:

CAN_SetRxFilter(&can_pal1_instance,CAN_MSG_ID_STD,4, 0x7FF);

CAN_SetRxFilter(&can_pal1_instance,CAN_MSG_ID_STD,5, 0x7EF);

CAN_SetRxFilter(&can_pal1_instance,CAN_MSG_ID_STD,6, 0x7FF);

for ID_EXT:

CAN_SetRxFilter(&can_pal1_instance,CAN_MSG_ID_ETX,4, 0xFFFFFFFF);

CAN_SetRxFilter(&can_pal1_instance,CAN_MSG_ID_ETX,5, 0xFFFFFFEF);

CAN_SetRxFilter(&can_pal1_instance,CAN_MSG_ID_ETX,6, 0xFFFFFFFF);

BR, Petr

117 Views
Contributor II

Dear Petr,

Thank you very much, the reception of CAN ID can work as I expected.

0 Kudos