Skip to main content
MAlam.2
Associate II
July 5, 2021
Question

I need to configure CAN filters in such a way that only ID 0x80 and IDs between 0x200 and 0x300 passes all others are not allowed to be passed. How to do that?

  • July 5, 2021
  • 1 reply
  • 1418 views

I tried in this way but the problem is only 200-300 can pass but 80h is not passed. if i use if else then only 80h is passed not 200-300h. So, the problem is i can pass either 80h or 200h-300h. Not both 80h and 200-300h.

#define Filter_ID1  0x80

#define Filter_ID2  0x200

#if Filter_ID1

      sFilterConfig.FilterMode = CAN_FILTERMODE_IDMASK;

      sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;

      sFilterConfig.FilterBank = 0;

      sFilterConfig.FilterIdHigh=0x80<<5;

      sFilterConfig.FilterMaskIdHigh=0xff<<5;

      sFilterConfig.FilterIdLow = 0x0000;

      sFilterConfig.FilterMaskIdLow = 0x0000;

      sFilterConfig.FilterFIFOAssignment = CAN_RX_FIFO0;

      sFilterConfig.FilterActivation = ENABLE;

#endif

#if Filter_ID2

      sFilterConfig.FilterMode = CAN_FILTERMODE_IDMASK;

      sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;

      sFilterConfig.FilterBank = 1;

      sFilterConfig.FilterIdHigh=0x200<<5;

      sFilterConfig.FilterMaskIdHigh=0x300<<5;

      sFilterConfig.FilterIdLow = 0x0000;

      sFilterConfig.FilterMaskIdLow = 0x0000;

      sFilterConfig.FilterFIFOAssignment = CAN_RX_FIFO0;

      sFilterConfig.FilterActivation = ENABLE;

#endif

This topic has been closed for replies.

1 reply

Javier1
Principal
July 5, 2021

Maybe this links are usefull for you:

//usage of can filters
 
 //https://schulz-m.github.io/2017/03/23/stm32-can-id-filter/
 
 //https://www.diller-technologies.de/stm32.html <-----this guy knows better

If i remember correctly you can only use mask mode or individual addresses mode but not both?

  sFilterConfig.FilterMode

hit me up in https://www.linkedin.com/in/javiermuñoz/
Javier1
Principal
July 5, 2021

Idea, if youre using a board with two canbus peripheral available, you could wire them up together to the same transceiver lines and use Filter_ID1 in CAN1 and Filter_ID2 in CAN2

hit me up in https://www.linkedin.com/in/javiermuñoz/
MAlam.2
MAlam.2Author
Associate II
July 5, 2021

unfortunately i am using nucleo stm32F303Re and it has only one CAN bus peripheral. But i have another idea is it technically possible that i use rxfifo 0 for 0x80 and rxfifio1 for 0x200-0x300?