cancel
Showing results for 
Search instead for 
Did you mean: 

CAN Bus Mask and ID

FJB2069
Associate II

Trying to understand how to setup the ID and Mask with Extended ID. I want allow messages with id's 0x1E02xxxx. So 0x1E021234 would be accepted and 0x1E031234 rejected.

  1.   /*##-2- Configure the CAN Filter ###########################################*/
  2.   sFilterConfig.FilterNumber = 0;
  3.   sFilterConfig.FilterMode = CAN_FILTERMODE_IDMASK;
  4.   sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;
  5.   sFilterConfig.FilterIdHigh = 0x1E02;
  6.   sFilterConfig.FilterIdLow = 0x0000;
  7.   sFilterConfig.FilterMaskIdHigh = 0x1FFF;
  8.   sFilterConfig.FilterMaskIdLow = 0x0000;
  9.   sFilterConfig.FilterFIFOAssignment = 0;
  10.   sFilterConfig.FilterActivation = ENABLE;
  11.   sFilterConfig.BankNumber = 14;

2 REPLIES 2

I think you need to review the data you capture with an open filter, the Ext ID is 29 bits, and arranged thusly

0690X00000DYifmQAD.jpg

I suspect your High Order bits are in the wrong spot, and need to be leftward some what, you can also mask/check the IDE bit

Guessing 0x1E02 << 3 and 0x1FFF << 3

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
FJB2069
Associate II

I figured it out:

High filter: contains only  bits 28-13 of id, so you need to <<  id by 3, mask off bits 12-0 and then >> by 16.

Low filter:  contains bits 12-0 plus IDE, RTR,  O.  So again shift ID <<3 and then mask off last three bits (IDE, RTR, 0)

If I have the Extended Id 0x1E02533 and want to only allow this specific address:

uint32_t EXID=0x1E02533;

sFilterConfig.FilterIdHigh = (uint16_t)((EXID << 3 & 0xFFFE0000)>>16);

sFilterConfig.FilterIdLow =  ((EXID << 3 & 0x0000FFF8));

sFilterConfig.FilterMaskIdHigh = 0xFFFF;

sFilterConfig.FilterMaskIdLow = 0XFFF8; 

Further, if you want to allow a range of Extended Id's that start with 0x1E02xxxx you only need to change your mask bits:

uint32_t EXID=0x1E02533;

sFilterConfig.FilterIdHigh = (uint16_t)((EXID << 3 & 0xFFFE0000)>>16);

sFilterConfig.FilterIdLow =  ((EXID << 3 & 0x0000FFF8));

sFilterConfig.FilterMaskIdHigh = 0xFFFE;

sFilterConfig.FilterMaskIdLow = 0X0000;