新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > 關(guān)于STM32中CAN1_RX0_IRQn和CAN1_RX1_IRQn的使用

關(guān)于STM32中CAN1_RX0_IRQn和CAN1_RX1_IRQn的使用

作者: 時間:2016-11-19 來源:網(wǎng)絡(luò) 收藏
“如果你用的CAN引腳是PA11和PA12,接收中斷用CAN1_RX0_IRQn。如果CAN引腳用的是PB8和PB9,也就是用重定義的引腳,接收中斷用CAN1_RX1_IRQn。由于PA11和PA12也是USB的引腳,所以非互聯(lián)型且?guī)AN控制器的微控制器的庫文件在起名字時用了USB_LP_CAN1_RX0_IRQn。”

以上內(nèi)容參考于網(wǎng)絡(luò),后經(jīng)證實,以上說法是不正確的,理由如下:

本文引用地址:http://butianyuan.cn/article/201611/318094.htm

STM32有2個3級深度的接收緩沖區(qū):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; //關(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);
//
}



關(guān)鍵詞: STM32CA

評論


技術(shù)專區(qū)

關(guān)閉