STM32F042K6的CAN接收中断进不去,求教 最近刚接触与CAN通讯相关的项目, 对着方面不是太了解, 在调STM32F042K6的CAN通讯驱动时, 死活进不了接收中断(发送中断是可以的), 希望大家不吝敕教,谢谢!!! 下面是配置代码: /******************************************************************************* ****输入: 无 ****输出: 无 ****端口: CAN_RX~~PA11; CAN_TX~~PA12; ****说明: CAN通讯初始化 ****名称: can_init();// ****作者: *******************************************************************************/ void can_init(void) // { GPIO_InitTypeDef GPIO_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; CAN_InitTypeDef CAN_InitStructure; CAN_FilterInitTypeDef CAN_FilterInitStructure; //CAN中断使能和优先级设置 NVIC_InitStructure.NVIC_IRQChannel = CEC_CAN_IRQn; NVIC_InitStructure.NVIC_IRQChannelPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); //CAN时钟配置 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN, ENABLE); //CAN端口复用 GPIO_PinAFConfig(GPIOA,GPIO_PinSource11,GPIO_AF_4); GPIO_PinAFConfig(GPIOA,GPIO_PinSource12,GPIO_AF_4); //CAN_RX端口配置 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOA, &GPIO_InitStructure); //CAN_TX端口配置 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOA, &GPIO_InitStructure); //CAN_STB端口初始化 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOA, &GPIO_InitStructure); CAN_STB_OL(); // //CAN单元设置 CAN_InitStructure.CAN_TTCM = DISABLE; CAN_InitStructure.CAN_ABOM = DISABLE; CAN_InitStructure.CAN_AWUM = DISABLE; CAN_InitStructure.CAN_NART = ENABLE; CAN_InitStructure.CAN_RFLM = DISABLE; CAN_InitStructure.CAN_TXFP = DISABLE; CAN_InitStructure.CAN_Mode = CAN_Mode_Normal;//CAN_Mode_Normal; //CAN波特率设置,500KHz@48MHz CAN_InitStructure.CAN_SJW = CAN_SJW_1tq; CAN_InitStructure.CAN_BS1 = CAN_BS1_8tq; CAN_InitStructure.CAN_BS2 = CAN_BS2_7tq; CAN_InitStructure.CAN_Prescaler = 6; CAN_Init(CAN, &CAN_InitStructure); //CAN过滤器FIFO0配置 CAN_FilterInitStructure.CAN_FilterNumber = 0; CAN_FilterInitStructure.CAN_FilterMode = CAN_FilterMode_IdList; 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; CAN_FilterInitStructure.CAN_FilterActivation = ENABLE; CAN_FilterInit(&CAN_FilterInitStructure); //使能CAN中断 CAN_ClearITPendingBit(CAN, CAN_IT_FF0); CAN_ITConfig(CAN, CAN_IT_TME, ENABLE); CAN_ITConfig(CAN, CAN_IT_FMP0, ENABLE); CAN_ITConfig(CAN, CAN_IT_FF0, ENABLE); } /******************************************************************************* ****输入: 无 ****输出: 无 ****端口: CAN_RX~~PA11; CAN_TX~~PA12; ****说明: CAN中断服务函数 ****名称: CEC_CAN_IRQHandler();// ****作者: *******************************************************************************/ void CEC_CAN_IRQHandler(void) { u8 i = 0; ** if (CAN_GetITStatus(CAN, CAN_IT_TME) != 0) { CAN_ClearITPendingBit(CAN, CAN_IT_TME); i++; } if (CAN_GetITStatus(CAN, CAN_IT_FMP0) != 0) { *** CAN_ClearITPendingBit(CAN, CAN_IT_FMP0); i++; } if (CAN_GetITStatus(CAN, CAN_IT_FF0) != 0) { CAN_ClearITPendingBit(CAN, CAN_IT_FF0); i++; } if (CAN_GetITStatus(CAN, CAN_IT_FOV0) != 0) { CAN_ClearITPendingBit(CAN, CAN_IT_FOV0); i++; } } 以上代码调试时,星号处是打的断点, 用CAN分析仪发数据过来, 我的代码却进不了接收中断, 确定是有数据过来的! 麻烦大家帮忙看看哪里搞错了, 非常感谢!!! |
【STM32F0开发日志/评测/笔记】+互补PWM波的产生
STM32F030 PB14和PB15无法输出PWM求助
【STM32F030探索套件】序列之五 外部中断
【STM32F0开发日志---二】+ucosii.2.92移植在STM32F030
上传个STM32F0+5110+内部温度传感器的菜鸟实例
【STM32F030探索套件使用问题】STM32F030 SPI方式驱动ST7565LCD失败
求一份STM32F051 I2C驱动LCD 12864的例程
STM32F0 M0 向结构体赋值进入HardFault异常
STM32F0 ADC-DMA方式采集2路数据时出现问题
STM32F030C8T6,TIM16定时慢很多问题?
NORMAL模式的话,两边要接好线路,匹配电阻也用上;
CAN_FilterInitStructure.CAN_FilterMode = CAN_FilterMode_IdList;===》改成
CAN_FilterInitStructure.CAN_FilterMode = CAN_FilterMode_IdMask; 验证下
不然你那边发过来的ID要跟这边FILTER设置的一模一样,否则收不到收据;
官方有CAN历程可以参考;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
SYSCFG->CFGR1 |= SYSCFG_CFGR1_PA11_PA12_RMP;//PA11 and PA12 remap on QFN28 and TSSOP20 packages
这两行代码才行。还有波特率也搞错了,移植F1的代码,时钟用了36M的,改成用48M算,接收没问题了
朋友, 你用的片子应该是20Pin的吧, 按照参考手册上说的, 只有20pin的才需要加你说的这两句,我这个用的是32pin的...
我认为问题应该还是出在这两个脚的配置上面
上拉我试过了, 不行......
好吧,你用的是什么芯片,型号多少
谢谢提示
好像不对,还要研究下,我用USB CAN调试工具可以,但用I.MX6发出来的确收不到,发送的I.MX6能收到,哎