關(guān)于STM32中CAN1_RX0_IRQn和CAN1_RX1_IRQn的使用
以上內(nèi)容參考于網(wǎng)絡(luò),后經(jīng)證實(shí),以上說法是不正確的,理由如下:
本文引用地址:http://m.butianyuan.cn/article/201611/318094.htmSTM32有2個(gè)3級(jí)深度的接收緩沖區(qū):FIFO0和FIFO1,每個(gè)FIFO都可以存放3個(gè)完整的報(bào)文,它們完全由硬件來管理。如果是來自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; //關(guān)聯(lián)FIFO0
CAN_FilterInitStructure.CAN_FilterActivation = ENABLE;
CAN_FilterInit(&CAN_FilterInitStructure);
CAN_FilterInitStructure.CAN_FilterNumber = 14;
CAN_FilterInitStructure.CAN_FilterFIFOAssignment = 1; //關(guān)聯(lián)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. 中斷處理函數(shù)
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);
//
}
評(píng)論