Skip to main content
JBond.1
Senior
July 9, 2021
Question

Odd and Even CAN bus ID's FilterConfig

  • July 9, 2021
  • 1 reply
  • 739 views

Hi, I am working with STM32F103 and configured CAN filter to receive ODD and EVEN ID's to FIFO0 and FIFO1 accordingly:

 CAN_FilterTypeDef sFilterConfig;
 sFilterConfig.SlaveStartFilterBank = 28;
 sFilterConfig.FilterActivation = ENABLE;
 sFilterConfig.FilterMode = CAN_FILTERMODE_IDMASK;
 sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;
 sFilterConfig.FilterBank = 0;
 sFilterConfig.FilterFIFOAssignment = CAN_RX_FIFO0;
 // odd IDs to FIFO0
 sFilterConfig.FilterIdHigh = (0x00000001 << 5);
 sFilterConfig.FilterIdLow = (0x00000000 << 5);
 sFilterConfig.FilterMaskIdHigh = (0x00000001 << 5);
 sFilterConfig.FilterMaskIdLow = (0x00000000 << 5);
 
 if (HAL_CAN_ConfigFilter(&hcan, &sFilterConfig) != HAL_OK)
 {
 Error_Handler();
 }
 
 sFilterConfig.FilterBank = 1;
 sFilterConfig.FilterFIFOAssignment = CAN_RX_FIFO1;
 // even IDs to FIFO1
 sFilterConfig.FilterIdHigh = (0x00000000 << 5);
 sFilterConfig.FilterIdLow = (0x00000000 << 5);
 sFilterConfig.FilterMaskIdHigh = (0x00000001 << 5);
 sFilterConfig.FilterMaskIdLow = (0x00000000 << 5);
 
 if (HAL_CAN_ConfigFilter(&hcan, &sFilterConfig) != HAL_OK)
 {
 Error_Handler();
 }
	
 if (HAL_CAN_Start(&hcan) != HAL_OK)
 {
 Error_Handler();
 }
	
 if (HAL_CAN_ActivateNotification(&hcan, CAN_IT_RX_FIFO0_MSG_PENDING) != HAL_OK)
 {
 Error_Handler();
 }
	
 if (HAL_CAN_ActivateNotification(&hcan, CAN_IT_RX_FIFO1_MSG_PENDING) != HAL_OK)
 {
 Error_Handler();
 }

Its not that easy to understand STM32 filter mask and ID's. So is filter configured correctly to receive ODD and EVEN ID's to FIFO0 and FIFO1?

Also previously I was using only FIFO0 to catch all CAN bus ID's. Does splitting filters to ODD and EVEN ID's into FIFO0 and FIFO1 should give better performance and less overflow chance?

This topic has been closed for replies.

1 reply

Bowman32
ST Employee
July 16, 2021

Hi @Community member​ 

It seems all code configuration is correct. However, you can refer to STM32F103 reference manual RM0008 section 24.7.4 Identifier filtering.

Bouraoui