完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我的CAN1的配置如下,不论怎么试都进不了中断函数。求大家帮忙看看
void My_CAN1_Init(uint32_t _baudRate) { //´´½¨ÉèÖýṹÌå GPIO_InitTypeDef GPIO_InitStructure; CAN_InitTypeDef CAN_InitStructure; CAN_FilterInitTypeDef CAN_FilterInitStructure; NVIC_InitTypeDef NVIC_InitStructure; #ifdef VECT_TAB_RAM /* Set the Vector Table base location at 0x20000000 / NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0); #else / VECT_TAB_FLASH / / Set the Vector Table base location at 0x08000000 */ NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0); #endif // RCC_ClocksTypeDef rcc_clocks; // RCC_GetClocksFreq(&rcc_clocks); // SystemInit(); //¿ªÆôGPIOºÍCAN1µÄʱÖÓ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA , ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11; //RX GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //ÉÏÀÊäÈë GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;//100MHz GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12; //TX GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //ÍÆÍìÊä³ö GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;//100MHz GPIO_Init(GPIOA, &GPIO_InitStructure); CAN_DeInit(CAN1); CAN_StructInit(&CAN_InitStructure); CAN_InitStructure.CAN_TTCM=DISABLE; //ʱ¼ä´¥·¢Ä£Ê½ CAN_InitStructure.CAN_ABOM=ENABLE; //×Ô¶¯ÀëÏß¹ÜÀí CAN_InitStructure.CAN_AWUM=DISABLE; //×Ô¶¯»½ÐÑģʽ CAN_InitStructure.CAN_NART=DISABLE; //·Ç×Ô¶¯ÖØ´«Ä£Ê½ CAN_InitStructure.CAN_RFLM=DISABLE; //½ÓÊÜFIFOËø¶¨Ä£Ê½ CAN_InitStructure.CAN_TXFP=ENABLE; //·¢ËÍFIFOģʽ CAN_InitStructure.CAN_Mode=CAN_Mode_Normal; //Õý³£Ä£Ê½ CAN_InitStructure.CAN_SJW=CAN_SJW_1tq; CAN_InitStructure.CAN_BS1=CAN_BS1_3tq; CAN_InitStructure.CAN_BS2=CAN_BS2_2tq; CAN_InitStructure.CAN_Prescaler= 6000000 / _baudRate; //²¨ÌØÂʹ«Ê½=72M/(2*(SJW+BS1+BS2)*Prescale) CAN_Init(CAN1, &CAN_InitStructure); //ÅäÖùýÂËÆ÷ CAN_FilterInitStructure.CAN_FilterNumber= 0; //Â˲¨Æ÷Ñ¡Ôñ0~13 CAN_FilterInitStructure.CAN_FilterMode=CAN_FilterMode_IdMask; //Ö¸¶¨¹ýÂËÆ÷Ϊ±êʶ·ûÆÁ±Îģʽ CAN_FilterInitStructure.CAN_FilterScale=CAN_FilterScale_32bit; //¹ýÂËÆ÷λ¿íΪ32λ CAN_FilterInitStructure.CAN_FilterIdHigh=0x0000; //Òª¹ýÂ˵ÄID¸ßλ CAN_FilterInitStructure.CAN_FilterIdLow= 0x0000; //Òª¹ýÂ˵ÄIDµÍλ CAN_FilterInitStructure.CAN_FilterMaskIdHigh= 0x0000; //¹ýÂËÆ÷ÆÁ±Î±êʶ·ûµÄ¸ß16λ CAN_FilterInitStructure.CAN_FilterMaskIdLow= 0x0000; //¹ýÂËÆ÷ÆÁ±Î±êʶ·ûµÄµÍ16λ CAN_FilterInitStructure.CAN_FilterFIFOAssignment= CAN_FilterFIFO0;//É趨ÁËÖ¸Ïò¹ýÂËÆ÷µÄFIFOΪ0 CAN_FilterInitStructure.CAN_FilterActivation=ENABLE; //¹ýÂËÆ÷ʹÄÜ CAN_FilterInit(&CAN_FilterInitStructure); //CAN1ÖжÏÅäÖà NVIC_InitStructure.NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); //CAN1 FIFOʹÄÜ CAN_ClearITPendingBit(CAN1,CAN_IT_FF0); CAN_ClearITPendingBit(CAN1,CAN_IT_FOV0); CAN_ITConfig(CAN1,CAN_IT_FMP0,ENABLE); } #define Get_Gryo_Data USB_LP_CAN1_RX0_IRQHandler void Get_Gryo_Data(void) { static int16_t x_angle_data, y_angle_data, z_angle_data, z_anglespeed_data; static float x_origin_angle, y_origin_angle, z_origin_angle, z_origin_anglespeed; CanRxMsg rx_message; if (CAN_GetITStatus(GRYO_CAN, CAN_IT_FMP0) != RESET) { CAN_Receive(GRYO_CAN, CAN_FIFO0, &rx_message); if ((rx_message.IDE == CAN_ID_STD) && (rx_message.RTR == CAN_RTR_DATA)) //标准帧、数据帧、数据长度为8 { if (rx_message.StdId == 0x401) { z_angle_data = ((rx_message.Data[1] 《《 8) | rx_message.Data[0]); x_angle_data = ((rx_message.Data[3] 《《 8) | rx_message.Data[2]); y_angle_data = ((rx_message.Data[5] 《《 8) | rx_message.Data[4]); z_origin_angle = z_angle_data / 10000.0 * RAD2DEG; x_origin_angle = x_angle_data / 10000.0 * RAD2DEG; y_origin_angle = y_angle_data / 10000.0 * RAD2DEG; gps_z_angle = z_origin_angle - gps_z_angle_offset; gps_x_angle = x_origin_angle; gps_y_angle = y_origin_angle; int_gps_z_angle = (uint16_t)gps_z_angle; int_gps_x_angle = (uint16_t)gps_x_angle; int_gps_y_angle = (uint16_t)gps_y_angle; } if (rx_message.StdId == 0x402) { z_anglespeed_data = ((rx_message.Data[5] 《《 8) | rx_message.Data[4]); z_origin_anglespeed = z_anglespeed_data / 32768.0 * GRYO_RANGE; gps_z_anglespeed = z_origin_anglespeed - gps_z_anglespeed_offset; int_gps_z_anglespeed = (uint16_t)gps_z_anglespeed; } } CAN_FIFORelease(GRYO_CAN, CAN_FIFO0); } |
|
|
|
只有小组成员才能发言,加入小组>>
调试STM32H750的FMC总线读写PSRAM遇到的问题求解?
1780 浏览 1 评论
X-NUCLEO-IHM08M1板文档中输出电流为15Arms,15Arms是怎么得出来的呢?
1621 浏览 1 评论
1081 浏览 2 评论
STM32F030F4 HSI时钟温度测试过不去是怎么回事?
728 浏览 2 评论
ST25R3916能否对ISO15693的标签芯片进行分区域写密码?
1679 浏览 2 评论
1938浏览 9评论
STM32仿真器是选择ST-LINK还是选择J-LINK?各有什么优势啊?
731浏览 4评论
STM32F0_TIM2输出pwm2后OLED变暗或者系统重启是怎么回事?
570浏览 3评论
596浏览 3评论
stm32cubemx生成mdk-arm v4项目文件无法打开是什么原因导致的?
556浏览 3评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-23 19:23 , Processed in 1.052404 second(s), Total 75, Slave 60 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号