stm32can总线应用程序调试通过仅供参考 下载本文

内容发布更新时间 : 2024/11/2 17:38:32星期一 下面是文章的全部内容请认真阅读。

STM32 CAN总线应用程序,调试通过仅供参考

1、打开STM32 CAN系统工作时钟

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE);

RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);

2、开放系统中断,根据实际情况选择

NVIC_InitStructure.NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn;

NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority

= 0;

NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

NVIC_Init(&NVIC_InitStructure); //

NVIC_InitStructure.NVIC_IRQChannel = CAN1_RX1_IRQn; //

NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 5; //

NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; //

NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //

NVIC_Init(&NVIC_InitStructure);

//NVIC_InitStructure.NVIC_IRQChannel = CAN1_SCE_IRQn;

//NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3;

//NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

//NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;