Skip to main content
Senior
August 7, 2025
Solved

FDCAN filter configuration to receive the ID 0x002 only

  • August 7, 2025
  • 1 reply
  • 265 views

hello @mƎALLEm ,

as you sugestted, i only want to receive a ID 0x002, so my code is like

// 设置接收过滤器
 FDCAN_FilterTypeDef sFilterConfig;
 sFilterConfig.IdType = FDCAN_STANDARD_ID;
 sFilterConfig.FilterIndex = 0;
 sFilterConfig.FilterType = FDCAN_FILTER_MASK;
 sFilterConfig.FilterConfig = FDCAN_FILTER_TO_RXFIFO0;
 sFilterConfig.FilterID1 = 0x002; // 设置过滤器ID1
 sFilterConfig.FilterID2 = 0x7ff; // 设置过滤器ID2
 if (HAL_FDCAN_ConfigFilter(&hfdcan1, &sFilterConfig) != HAL_OK)
 {
 Error_Handler();
 }

 if(HAL_FDCAN_ConfigGlobalFilter(&hfdcan1, FDCAN_REJECT, FDCAN_REJECT, FDCAN_FILTER_REMOTE, FDCAN_FILTER_REMOTE) != HAL_OK)
 {
 Error_Handler();
 }

but now, i can not receive any message.

when i not add 

HAL_FDCAN_ConfigGlobalFilter()
i can receive every message.
 
but i only want to receive 0x002.
 
how should i do?
 
thanks.
 
Best answer by dqsh06

hello, 

i got the solution.

1. the filter setting as below

 // 设置接收过滤器
 FDCAN_FilterTypeDef sFilterConfig;
 sFilterConfig.IdType = FDCAN_STANDARD_ID;
 sFilterConfig.FilterIndex = 0;
 sFilterConfig.FilterType = FDCAN_FILTER_MASK;
 sFilterConfig.FilterConfig = FDCAN_FILTER_TO_RXFIFO0;
 sFilterConfig.FilterID1 = 0x002; // 设置过滤器ID1
 sFilterConfig.FilterID2 = 0x7ff; // 设置过滤器ID2
 if (HAL_FDCAN_ConfigFilter(&hfdcan1, &sFilterConfig) != HAL_OK)
 {
 Error_Handler();
 }

 if(HAL_FDCAN_ConfigGlobalFilter(&hfdcan1, FDCAN_REJECT, FDCAN_REJECT, FDCAN_REJECT_REMOTE, FDCAN_REJECT_REMOTE) != HAL_OK)
 {
 Error_Handler();
 }

the MX_FDCAN1_Init(void) should modify to 

hfdcan1.Init.StdFiltersNbr = 1;

the original generated by cubeMX is hfdcan1.Init.StdFiltersNbr = 0;  change to 1, then it take affect.

this is the solution.

dqsh06_0-1754616990382.png

only 0x002 message can be received.

 

1 reply

dqsh06AuthorBest answer
Senior
August 8, 2025

hello, 

i got the solution.

1. the filter setting as below

 // 设置接收过滤器
 FDCAN_FilterTypeDef sFilterConfig;
 sFilterConfig.IdType = FDCAN_STANDARD_ID;
 sFilterConfig.FilterIndex = 0;
 sFilterConfig.FilterType = FDCAN_FILTER_MASK;
 sFilterConfig.FilterConfig = FDCAN_FILTER_TO_RXFIFO0;
 sFilterConfig.FilterID1 = 0x002; // 设置过滤器ID1
 sFilterConfig.FilterID2 = 0x7ff; // 设置过滤器ID2
 if (HAL_FDCAN_ConfigFilter(&hfdcan1, &sFilterConfig) != HAL_OK)
 {
 Error_Handler();
 }

 if(HAL_FDCAN_ConfigGlobalFilter(&hfdcan1, FDCAN_REJECT, FDCAN_REJECT, FDCAN_REJECT_REMOTE, FDCAN_REJECT_REMOTE) != HAL_OK)
 {
 Error_Handler();
 }

the MX_FDCAN1_Init(void) should modify to 

hfdcan1.Init.StdFiltersNbr = 1;

the original generated by cubeMX is hfdcan1.Init.StdFiltersNbr = 0;  change to 1, then it take affect.

this is the solution.

dqsh06_0-1754616990382.png

only 0x002 message can be received.