STM32Cube的CAN滤波如何设置,需要只让两个需要的ID进去中断,其他的全部过滤。请问如何设置? /*##-2- Configure the CAN1 Filter ###########################################*/ sFilterConfig.FilterNumber = 0; sFilterConfig.FilterMode = CAN_FILTERMODE_IDMASK; sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT; sFilterConfig.FilterIdHigh = AllowID_F507<<5; sFilterConfig.FilterIdLow = 0|CAN_ID_STD;; sFilterConfig.FilterMaskIdHigh = 0xFFFF; sFilterConfig.FilterMaskIdLow = 0xFFFF; sFilterConfig.FilterFIFOAssignment = CAN_FIFO0; sFilterConfig.FilterActivation = ENABLE; sFilterConfig.BankNumber = 0; HAL_CAN_ConfigFilter(&hcan, &sFilterConfig); /*##-2- Configure the CAN1 Filter ###########################################*/ sFilterConfig.FilterNumber = 1; sFilterConfig.FilterMode = CAN_FILTERMODE_IDMASK; sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT; sFilterConfig.FilterIdHigh = AllowID2_F507<<5; sFilterConfig.FilterIdLow = 0|CAN_ID_STD;; sFilterConfig.FilterMaskIdHigh = 0xFFFF; sFilterConfig.FilterMaskIdLow = 0xFFFF; sFilterConfig.FilterFIFOAssignment = CAN_FIFO0; sFilterConfig.FilterActivation = ENABLE; sFilterConfig.BankNumber = 0; HAL_CAN_ConfigFilter(&hcan, &sFilterConfig); HAL_CAN_Receive_IT(&hcan,CAN_FIFO0); 芯片是用STM32F103VET的。 |
既然这样 你可以设置2个滤波器,使用标识符列模式。
sFilterConfig.FilterMode = CAN_FilterMode_IdList;
。。。
另外,列表模式下的话,
sFilterConfig.FilterMaskIdHigh = 0x。。。;
sFilterConfig.FilterMaskIdLow = 0x。。。 应该是另外一个ID.
评分
查看全部评分
谢谢回复
谢谢回答,最近在做STM32F334的CAN测试,不过问题已解决