OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 699|回复: 1

CAN接收进不了中断,debug也跳不过去,发送正常,求大佬帮忙看看

[复制链接]

8

主题

66

帖子

0

精华

中级会员

Rank: 3Rank: 3

积分
323
金钱
323
注册时间
2016-7-12
在线时间
65 小时
发表于 2024-7-19 10:03:38 | 显示全部楼层 |阅读模式
1金钱
void Mcaro_CAN_Init(void)
{

     RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);

     CAN_InitTypeDef CAN_InitStruct;
     CAN_InitStruct.CAN_ABOM = ENABLE; /*BUS-off硬件复位*/
     CAN_InitStruct.CAN_AWUM = DISABLE; /*硬件自动唤醒模式*/
     CAN_InitStruct.CAN_TTCM = DISABLE; /*时间触发通讯模式*/
     CAN_InitStruct.CAN_TXFP = DISABLE; /*标识符优先级模式*/
     CAN_InitStruct.CAN_NART = ENABLE;  /*报文自动重传*/
     CAN_InitStruct.CAN_RFLM = DISABLE; /*接收FIFO锁定模式*/
     CAN_InitStruct.CAN_Mode = CAN_Mode_Normal;
     CAN_InitStruct.CAN_BS1 = CAN_BS1_3tq;
     CAN_InitStruct.CAN_BS2 = CAN_BS2_4tq;
     CAN_InitStruct.CAN_Prescaler = 9;
     CAN_InitStruct.CAN_SJW = CAN_SJW_1tq;
     CAN_Init(CAN1, &CAN_InitStruct);

     CAN_FilterInitTypeDef CAN_FilterInitStruct;
     CAN_FilterInitStruct.CAN_FilterActivation = ENABLE; /*过滤器激活*/
     CAN_FilterInitStruct.CAN_FilterFIFOAssignment = CAN_Filter_FIFO0;
     CAN_FilterInitStruct.CAN_FilterIdHigh = 0x0000;
     CAN_FilterInitStruct.CAN_FilterIdLow = 0x0000;
     CAN_FilterInitStruct.CAN_FilterMaskIdHigh = 0x0000;
     CAN_FilterInitStruct.CAN_FilterMaskIdLow = 0x0000;
     CAN_FilterInitStruct.CAN_FilterMode = CAN_FilterMode_IdMask;
     CAN_FilterInitStruct.CAN_FilterNumber = 0;
     CAN_FilterInitStruct.CAN_FilterScale = CAN_FilterScale_32bit;
     CAN_FilterInit(&CAN_FilterInitStruct);

     CAN_ITConfig(CAN1, CAN_IT_TME | CAN_IT_FMP0 | CAN_IT_FF0 | CAN_IT_FOV0
                                   | CAN_IT_FMP1 | CAN_IT_FF1 | CAN_IT_FOV1
                                   | CAN_IT_EWG | CAN_IT_LEC | CAN_IT_ERR  
                                   |    CAN_IT_WKU | CAN_IT_SLK, ENABLE);
     NVIC_InitTypeDef NVIC_InitStruct;
     NVIC_InitStruct.NVIC_IRQChannel = CAN1_RX1_IRQn;
     NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
     NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 0;
     NVIC_InitStruct.NVIC_IRQChannelSubPriority = 0;
     NVIC_Init(&NVIC_InitStruct);

}

/**
* @brief CANFIFO中断
*/
void CAN1_RX1_IRQHandler(void)
{
     /*数据接收中断*/
     if (CAN_GetITStatus(CAN1, CAN_IT_FMP0) == SET)
     {

          CAN_Receive(CAN1, CAN_FIFO0, &RxMessage);
              Mcaro_GPIO_Bitset(LED1, 0);
              delay_ms(100);
              Mcaro_GPIO_Bitset(LED1, 1);


          CAN_ClearITPendingBit(CAN1,CAN_IT_FMP0);
     }

}


正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

10

主题

215

帖子

0

精华

论坛元老

Rank: 8Rank: 8

积分
5784
金钱
5784
注册时间
2016-12-19
在线时间
742 小时
发表于 2024-7-20 08:31:47 | 显示全部楼层
应该是初始化问题,最好找个能用的代码试一下,can接受还是比较麻烦的,比串口复炸
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-1-31 14:52

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表