cancel
Showing results for 
Search instead for 
Did you mean: 

how to set CAN filter mask?

PNova.2
Associate II

Hello

I'm trying to set a filter but I can't.
If I set, for example, the value 0x3 - all IDs with set bits 0 and 1 - (0x7, 0x13, 0xF, 0xF03......) pass through the filter.
I guess I didn't understand this masking. Can you tell me what I'm doing wrong?

I proceeded according to: https://www.youtube.com/watch?v=JfWlIY0zAIc

 

  sFilterConfig.FilterBank = 0;
  sFilterConfig.FilterMode = CAN_FILTERMODE_IDMASK;
  sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;
  sFilterConfig.FilterIdHigh = 0x03<<5;
  sFilterConfig.FilterIdLow = 0;
  sFilterConfig.FilterMaskIdHigh = 0x03<<5;
  sFilterConfig.FilterMaskIdLow = 0;
  sFilterConfig.FilterFIFOAssignment = CAN_RX_FIFO0;
  sFilterConfig.FilterActivation = ENABLE;
  sFilterConfig.SlaveStartFilterBank = 14;

 

2 REPLIES 2
Foued_KH
ST Employee

Hello @PNova.2 , 

FilterMaskIdHigh is the Higher 16 Bits of the MASK register. The value set in this register will enable the comparison of that particular bit in the ID register to that of the incoming ID.

When a message is transmitted on a CAN bus, its ID is compared with the filter mask to determine if it should be accepted or rejected. The bits in the filter mask that are set to 1 indicate which bits in the ID are important for filtering, while the bits set to 0 indicate which bits can be ignored.

In summary, the filter mask is used to specify which bits in the message ID are important for filtering, and which bits can be ignored. This allows for selective filtering of messages on a CAN bus.

Foued

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Thanks for the explanation.

So:

sFilterConfig.FilterIdHigh = 0x103<<5;
sFilterConfig.FilterIdLow = 0;
sFilterConfig.FilterMaskIdHigh = 0xFFFF<<5;//only ID in FilterIdHigh
sFilterConfig.FilterMaskIdLow = 0;

sFilterConfig.FilterIdHigh = 0x103;
sFilterConfig.FilterIdLow = 0;
sFilterConfig.FilterMaskIdHigh = 0x0;//any ID
sFilterConfig.FilterMaskIdLow = 0;

sFilterConfig.FilterIdHigh = 0x103;
sFilterConfig.FilterIdLow = 0;
sFilterConfig.FilterMaskIdHigh = 0xFF00<<5;//  ID 0x100 - 0x1FF
sFilterConfig.FilterMaskIdLow = 0;