Filtering and Masking in CAN bus

Hi,
I am working with flexcan in NXP's board. I am trying to read an input from a different board whose ID is 0x760. (29-bit identifier)
I am not able to understand the filtering and masking concept from the demo code.

 Serial.println(CAN.init_Mask(1, 1, 0xFFFFFFFF));
 Serial.println(CAN.init_Mask(0, 1, 0x1FFFFC08));
 Serial.println(CAN.init_Filt(0, 1, 398722056));

This is the demo code. If I do not use this demo code so I kinda receiving the values from a different ID altogether.

I want to read the data Byte(int) only one byte which is being sent from 0x760. How would I do a filter for this function? Can anyone help me? :confused:

Thanks in advance.
Thanks and Regards
Niranjan

This is the demo code.

That snippet reads data from some undefined device, and outputs some unknown data.

If I do not use this demo code so I kinda receiving the values from a different ID altogether.

When you use some other code, you get different results.

Without knowing what device you are talking to, what output you get using the posted snippet, and what code you are actually using, there isn't a snowball's chance in hell that anyone can explain anything to you.

I want to read the data Byte(int) only one byte

So, do that. I can't even make sense of that collection of words, so don't expect me to help you.

hope fully this explanation should help you understand how that function works a bit better (forget where I have got it! )

CAN Masks & Filters 101:

  1. The Rx Mask is nothing more than a bit level switch to enable or disable the filter bits.
    Eg/
    (assume 11 bit Id)
    If the Mask is set to a value of 0b00000000111 (0x0007) then only bits 0,1 & 2 of the filter bits will be used to filter the received Id against.

  2. The Rx filter is used to check the received CAN Id against. If a match is detected on the active filter bits, then the received CAN message is placed in the Rx buffer, else the CAN message is discarded.

(assume 11 bit Id)
Eg 1/
Mask Value: 0b11111111111 (0x03FF) (all filter bits enabled)
Filter Value: 0b11111111111 (0x03FF)
The Rx buffer will only receive CAN frames with an Id of 0x03FF

Eg 2/
Mask Value: 0b11111111111 (0x03FF) (all filter bits enabled)
Filter Value: 0b11111111110 (0x03FE)
The Rx buffer will only receive CAN frames with an Id of 0x03FE

Eg 3/
Mask Value: 0b11111111110 (0x03FE)
Filter Value: 0b11111111111 (0x03FF)
The Rx buffer will receive CAN frames with an Id of 0x03FE or 0x03FF as bit 0 of the filter bit is disabled.

Eg 4/
Mask Value: 0b11111111110 (0x03FE)
Filter Value: 0b11111111110 (0x03FE)
The Rx buffer will receive CAN frames with an Id of 0x03FE or 0x03FF as bit 0 of the filter bit is disabled.

Eg 5/
Mask Value: 0b11111111111 (0x03FF) (all filter bits enabled)
Filter Value: 0b11111111000 (0x03F8)
The Rx buffer will only receive CAN frames with an Id of 0x03F8

Eg 6/
Mask Value: 0b11111111000 (0x03F8)
Filter Value: 0b11111111000 (0x03F8)
The Rx buffer will receive CAN frames with an Id of 0x03F8,0x03F9,0x03FA,0x03FB,0x03FC,0x03FD,0x03FE,0x03FF as bit 0,1 & 2 of the filter bits are disabled.

Eg 7/
Mask Value: 0b11111111111 (0x03FF) (all filter bits enabled)
Filter Value: 0b00000000000 (0x0000)
The Rx buffer will only receive CAN frames with an Id of 0x000

Eg 8/
Mask Value: 0b11111111111 (0x03FF) (all filter bits enabled)
Filter Value: 0b00000000001 (0x0001)
The Rx buffer will only receive CAN frames with an Id of 0x001

Eg 9/
Mask Value: 0b11111111000 (0x03F8)
Filter Value: 0b00000000000 (0x0000)
The Rx buffer will receive CAN frames with an Id of 0x000,0x001,0x002,0x003,0x004,0x005,0x006,0x007 as bit 0,1 & 2 of the filter bits are disabled.

Eg 10/
Mask Value: 0b00000000111 (0x0007)
Filter Value: 0b00000000000 (0x0000)
The Rx buffer will receive CAN frames that end either 0,1,2,3,4,5,6,7 (0x121 = accepted, 0x0128 = discarded)

3 Likes