cancel
Showing results for 
Search instead for 
Did you mean: 

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

Emilmart
Senior

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

1 ACCEPTED SOLUTION

Accepted Solutions

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

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

View solution in original post

3 REPLIES 3

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

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

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 :