Skip to main content
Emilmart
Associate III
February 24, 2022
Solved

CAN bus apply filter on extended ID only (discard standard ID)

Hi,

I'm using extended ID for my CAN bus. I want to filter ID 0x12.

My code is working well when I receive an extended ID frame with containing the ID 0x12. If the received ID is something else than 0x12, the FIFO callback isn't triggered.

CAN_FilterTypeDef sFilterConfig;
 
 
 sFilterConfig.FilterBank = 0;
 
 sFilterConfig.FilterMode = CAN_FILTERMODE_IDMASK;
 
 sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;
 
 sFilterConfig.FilterIdHigh = 0;
 
 sFilterConfig.FilterIdLow = 0x12 << 3;
 
 sFilterConfig.FilterMaskIdHigh = 0;
 
 sFilterConfig.FilterMaskIdLow = 0xFF << 3;
 
 sFilterConfig.FilterFIFOAssignment = CAN_RX_FIFO0;
 
 sFilterConfig.FilterActivation = ENABLE;
 
 sFilterConfig.SlaveStartFilterBank = 27;
 
 
HAL_CAN_ConfigFilter(&hcan1, &sFilterConfig);

However, when I receive a standard ID frame, whatever the ID is, my FIFO callback is triggered.

So I'd like to discard all the standard ID frames that I receive so that they won't trigger my callback, how could I do it ?

Thanks

This topic has been closed for replies.
Tesla DeLorean
Tesla DeLoreanBest answer
Guru
February 24, 2022

Should be able to add the IDE bit to mask/compare​

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..

3 replies

Tesla DeLorean
Tesla DeLoreanBest answer
Guru
February 24, 2022

Should be able to add the IDE bit to mask/compare​

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Emilmart
EmilmartAuthor
Associate III
February 24, 2022

thanks clive, I hadn't thought about it. now it works with filtering/masking the IDE bit:

sFilterConfig.FilterIdLow = 0x12 << 3 | 0b100;   

sFilterConfig.FilterMaskIdLow = 0xFF << 3 | 0b100;

here's a pic that helps to understand :