1.CAN IO RX TX 的设定和重映射
GPIO_PinRemapConfig(GPIO_Remap2_CAN, ENABLE); //端口重映射到PD0,PD1
2.clock CAN IO CLOCK 的开启
、*-------gpio for can------------*/
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_AFIO, ENABLE);
CAN 自身CLOCK 的开启、
/* CAN Periph clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN, ENABLE);
3.CAN 接收中断 函数 USB_LP_CAN_RX0_IRQHandler()
及其 向UCOS 系统的注册
/*Set ISR for CAN*/
BSP_IntVectSet(BSP_INT_ID_USB_LP_CAN_RX0,USB_LP_CAN_RX0_IRQHandler);
BSP_IntEn(BSP_INT_ID_USB_LP_CAN_RX0);
向CPU 注册
/* enabling interrupt */
NVIC_InitStructure.NVIC_IRQChannel=USB_LP_CAN_RX0_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
CAN 使能
/* CAN FIFO0 message pending interrupt enable */
CAN_ITConfig(CAN_IT_FMP0, ENABLE);
4.CAN 相关结构体即寄存器的初始化
/* CAN register init */
CAN_DeInit();
CAN_StructInit(&CAN_InitStructure);
阅读(5814) | 评论(0) | 转发(0) |