“假如你用的CAN引脚是PA11和PA12,接纳中止用CAN1_RX0_IRQn。假如CAN引脚用的是PB8和PB9,也便是用重界说的引脚,接纳中止用CAN1_RX1_IRQn。我们PA11和PA12也是USB的引脚,所以非互联型且带CAN控制器的微控制器的库文件在起名字时用了USB_LP_CAN1_RX0_IRQn。”
以上内容参阅于网络,后经证明,以上说法是不正确的,理由如下:
STM32有2个3级深度的接纳缓冲区:FIFO0和FIFO1,每个FIFO都可以寄存3个完好的报文,它们完全由硬件来办理。假如是来自FIFO0的接纳中止,则用CAN1_RX0_IRQn中止来处理。假如是来自FIFO1的接纳中止,则用CAN1_RX1_IRQn中止来处理。在CAN的初始化装备过程中,用CAN_FilterFIFOAssignment来挑选要运用FIFO。
示例如下:
1. 装备过滤器
CAN_FilterInitStructure.CAN_FilterNumber = 0;
CAN_FilterInitStructure.CAN_FilterMode = CAN_FilterMode_IdMask;
CAN_FilterInitStructure.CAN_FilterScale = CAN_FilterScale_32bit;
CAN_FilterInitStructure.CAN_FilterIdHigh = 0x0000;
CAN_FilterInitStructure.CAN_FilterIdLow = 0x0000;
CAN_FilterInitStructure.CAN_FilterMaskIdHigh = 0x0000;
CAN_FilterInitStructure.CAN_FilterMaskIdLow = 0x0000;
CAN_FilterInitStructure.CAN_FilterFIFOAssignment = 0; //相关FIFO0
CAN_FilterInitStructure.CAN_FilterActivation = ENABLE;
CAN_FilterInit(&CAN_FilterInitStructure);
CAN_FilterInitStructure.CAN_FilterNumber = 14;
CAN_FilterInitStructure.CAN_FilterFIFOAssignment = 1; //相关FIFO1
CAN_FilterInit(&CAN_FilterInitStructure);
2. 舱位CAN中止
/* IT Configuration for CAN1 */
CAN_ITConfig(CAN1, CAN_IT_FMP0, ENABLE);
CAN_ITConfig(CAN1, CAN_IT_FMP1, ENABLE);
/* IT Configuration for CAN2 */
CAN_ITConfig(CAN2, CAN_IT_FMP0, ENABLE);
CAN_ITConfig(CAN2, CAN_IT_FMP1, ENABLE);
3. 中止处理函数
void CAN1_RX0_IRQHandler(void)
{
CAN_Receive(CAN1, CAN_FIFO0, &CAN1_RxMsg);
//
}
void CAN1_RX1_IRQHandler(void)
{
CAN_Receive(CAN1, CAN_FIFO1, &CAN1_RxMsg);
//
}
void CAN2_RX0_IRQHandler(void)
{
CAN_Receive(CAN2, CAN_FIFO0, &CAN2_RxMsg);
//
}
void CAN2_RX1_IRQHandler(void)
{
CAN_Receive(CAN2, CAN_FIFO1, &CAN2_RxMsg);
//
}