About the use of CAN1_RX0_IRQn and CAN1_RX1_IRQn in STM32

Publisher:心灵的旅程Latest update time:2016-06-13 Source: eefocusKeywords:STM32  CAN Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
    "If you use CAN pins PA11 and PA12, use CAN1_RX0_IRQn for receive interrupts. If CAN pins PB8 and PB9 are used, that is, redefined pins, use CAN1_RX1_IRQn for receive interrupts. Since PA11 and PA12 are also USB pins, the library file for non-interconnected microcontrollers with CAN controllers uses USB_LP_CAN1_RX0_IRQn when naming them."

   The above content is referenced from the Internet. It has been confirmed that the above statement is incorrect for the following reasons:

    STM32 has two 3-level deep receive buffers: FIFO0 and FIFO1. Each FIFO can store 3 complete messages, which are completely managed by hardware. If the receive interrupt comes from FIFO0, it is processed by CAN1_RX0_IRQn interrupt. If the receive interrupt comes from FIFO1, it is processed by CAN1_RX1_IRQn interrupt. During the initialization configuration of CAN, use CAN_FilterFIFOAssignment to select the FIFO to use.

Here is an example:

1. Configure the filter
 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. Enable CAN interrupt

   /* 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. Interrupt handling function


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);
        //
}

Keywords:STM32  CAN Reference address:About the use of CAN1_RX0_IRQn and CAN1_RX1_IRQn in STM32

Previous article:assert_param function in STM32
Next article:Bitband operation in STM32

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号