“如果你用的CAN引腳是PA11和PA12,接收中斷用CAN1_RX0_IRQn。如果CAN引腳用的是PB8和PB9,也就是用重定義的引腳,接收中斷用CAN1_RX1_IRQn。由于PA11和PA12也是USB的引腳,所以非互聯(lián)型且?guī)AN控制器的微控制器的庫文件在起名字時(shí)用了USB_LP_CAN1_RX0_IRQn。”具體的定義可以參考stm32F10x.h文件,其中對(duì)不同型號(hào)的中斷有具體的定義。
本文引用地址:http://www.ex-cimer.com/article/201611/322717.htm示例如下:
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 = CAN_FIFO0;//關(guān)聯(lián)FIFO0
CAN_FilterInitStructure.CAN_FilterActivation = ENABLE;
CAN_FilterInit(&CAN_FilterInitStructure);
CAN_FilterInitStructure.CAN_FilterNumber = 14;
CAN_FilterInitStructure.CAN_FilterFIFOAssignment = CAN_FIFO1;//關(guān)聯(lián)FIFO1
CAN_FilterInit(&CAN_FilterInitStructure);
2. 開啟CAN中斷
CAN_ITConfig(CAN1, CAN_IT_FMP0, ENABLE);
CAN_ITConfig(CAN1, CAN_IT_FMP1, ENABLE);
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)論