您的位置 首页 主动

关于STM32中CAN中止的运用

如果你用的CAN引脚是PA11和PA12,接收中断用CAN1_RX0_IRQn。如果CAN引脚用的是PB8和PB9,也就是用重定义的引脚,接收中断用CAN1_RX1_IRQn。

“假如你用的CAN引脚是PA11和PA12,接纳中止用CAN1_RX0_IRQn。假如CAN引脚用的是PB8和PB9,也便是用重界说的引脚,接纳中止用CAN1_RX1_IRQn。因为PA11和PA12也是USB的引脚,所以非互联型且带CAN控制器的微控制器的库文件在起名字时用了USB_LP_CAN1_RX0_IRQn。”详细的界说能够参阅stm32F10x.h文件,其间对不同类型的中止有详细的界说。

示例如下:

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;//相关FIFO0

CAN_FilterInitStructure.CAN_FilterActivation = ENABLE;

CAN_FilterInit(&CAN_FilterInitStructure);


CAN_FilterInitStructure.CAN_FilterNumber = 14;

CAN_FilterInitStructure.CAN_FilterFIFOAssignment = CAN_FIFO1;//相关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. 中止处理函数

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

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/ziliao/zhudong/255975.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部