cancel
Showing results for 
Search instead for 
Did you mean: 

CAN Communication: Multiple Filters At Once

KMew
Senior III

Hello,

I am trying to work with the CAN filters and I am experimenting with various techniques. One thing I would like to do is have more than one filter on the same bus. For example, I would like to have the following message IDs be possible:

0x10 and 0x20

AND

0x111 to 0x555

So I would like to do two filters:

 sFilterConfig.IdType = FDCAN_STANDARD_ID;

 sFilterConfig.FilterIndex = 0;

 sFilterConfig.FilterType = FDCAN_FILTER_DUAL;

 sFilterConfig.FilterConfig = FDCAN_FILTER_TO_RXBUFFER;

 sFilterConfig.FilterID1 = 0x10;

 sFilterConfig.FilterID2 = 0x20;

 sFilterConfig.RxBufferIndex = 0;

 HAL_FDCAN_ConfigFilter(&hfdcan, &sFilterConfig);

 sFilterConfig.IdType = FDCAN_STANDARD_ID;

 sFilterConfig.FilterIndex = 0;

 sFilterConfig.FilterType = FDCAN_FILTER_RANGE;

 sFilterConfig.FilterConfig = FDCAN_FILTER_TO_RXBUFFER;

 sFilterConfig.FilterID1 = 0x111;

 sFilterConfig.FilterID2 = 0x555;

 sFilterConfig.RxBufferIndex = 0;

 HAL_FDCAN_ConfigFilter(&hfdcan, &sFilterConfig);

I know the code above would not work since the second configuration would overwrite the first. I would like to know what I have to do to make what I explained above possible.

For my testing, I am using an STM32H7B3I-EVAL board.

1 ACCEPTED SOLUTION

Accepted Solutions

sFilterConfig.FilterIndex  <- Enumerate properly

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

sFilterConfig.FilterIndex  <- Enumerate properly

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

Hello,

Thank you for the reply!

Would I also have to alter the initialization? For example:

 hfdcan.Init.StdFiltersNbr = 1; // <--- Change this to 2??

I've mainly used BxCAN peripheral, not the FDCAN one.

With BxCAN you could manage 28 filters, and split then between CAN1 / CAN2

Suggest you grep all FDCAN examples across H7 boards/libraries to use cases, and .C source of library to specifics.

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