我正在使用STM32F4Discovery套件构建一个简单的CAN接口。我设法对其进行了配置,以便可以传输 CAN 消息,但是,我一直无法接收它们。据我所知,要接收 CAN 消息,它必须通过接受过滤器。我想将过滤器设置为接受从 ID 0x700 到 0x7FF 的所有(标准,2.0A)消息。我该怎么做呢?
我已阅读参考手册,但我不知道如何实际配置过滤。
void CAN_FilterConfiguration(void) {
CAN_FilterInitTypeDef CAN_FilterInitStructure;
/* CAN2 filter configuration */
CAN_FilterInitStructure.CAN_FilterNumber = 1; // filter number = 1 (0<=x<=13)
CAN_FilterInitStructure.CAN_FilterMode = CAN_FilterMode_IdMask;
CAN_FilterInitStructure.CAN_FilterScale = CAN_FilterScale_16bit;
CAN_FilterInitStructure.CAN_FilterIdHigh = 0x0000;
CAN_FilterInitStructure.CAN_FilterIdLow = 0x0000;
CAN_FilterInitStructure.CAN_FilterMaskIdHigh = 0x0000;
CAN_FilterInitStructure.CAN_FilterMaskIdLow = 0x0000;
CAN_FilterInitStructure.CAN_FilterFIFOAssignment = CAN_FIFO0; // FIFO = 0
CAN_FilterInitStructure.CAN_FilterActivation = ENABLE;
CAN_FilterInit(&CAN_FilterInitStructure);
}