Skip to main content
KMew
Senior III
October 3, 2022
Solved

CAN Communication: Multiple Filters At Once

  • October 3, 2022
  • 3 replies
  • 3068 views

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.

This topic has been closed for replies.
Best answer by Tesla DeLorean

sFilterConfig.FilterIndex  <- Enumerate properly

3 replies

Tesla DeLorean
Tesla DeLoreanBest answer
Guru
October 3, 2022

sFilterConfig.FilterIndex  <- Enumerate properly

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

Hello,

Thank you for the reply!

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

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

Tesla DeLorean
Guru
October 3, 2022

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 (See Profile) Up vote any posts that you find helpful, it shows what's working..