欢迎来到天天文库
浏览记录
ID:47487547
大小:51.01 KB
页数:11页
时间:2020-01-12
《stm32 CAN总线例子》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、stm32CAN总线例子利用stm32实现了1个简单的CAN功能,使用了队列缓存can.c文件#include"includes.h"#defineGPIO_CANGPIOB#defineRCC_APB2Periph_GPIO_CANRCC_APB2Periph_GPIOB#defineGPIO_Pin_RXGPIO_Pin_8#defineGPIO_Pin_TXGPIO_Pin_9#defineGPIO_Remap_CANGPIO_Remap1_CAN1#defineMAX_MAIL_NUM3staticu8CAN_msg_num[MAX_MAIL_NUM];//发送邮
2、箱标记///***@briefConfigurestheCAN,transmitandreceivebypolling*@paramNone*@retval:PASSEDifthereceptioniswelldone,FAILEDinothercase*/voidCAN_config_init(void){CAN_InitTypeDefCAN_InitStructure;CAN_FilterInitTypeDefCAN_FilterInitStructure;/*CANregisterinit*/CAN_DeInit(CAN1);CAN_StructInit(&CAN_
3、InitStructure);/*CANcellinit*///36M250k速率CAN_InitStructure.CAN_TTCM=DISABLE;CAN_InitStructure.CAN_ABOM=DISABLE;CAN_InitStructure.CAN_AWUM=DISABLE;CAN_InitStructure.CAN_NART=DISABLE;CAN_InitStructure.CAN_RFLM=DISABLE;CAN_InitStructure.CAN_TXFP=DISABLE;CAN_InitStructure.CAN_Mode=CAN_Mode_No
4、rmal;CAN_InitStructure.CAN_SJW=CAN_SJW_1tq;CAN_InitStructure.CAN_BS1=CAN_BS1_12tq;CAN_InitStructure.CAN_BS2=CAN_BS2_3tq;CAN_InitStructure.CAN_Prescaler=9;CAN_Init(CAN1,&CAN_InitStructure);/*CANfilterinit*/CAN_FilterInitStructure.CAN_FilterNumber=0;CAN_FilterInitStructure.CAN_FilterMode=CA
5、N_FilterMode_IdMask;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_Filte
6、rInitStructure.CAN_FilterFIFOAssignment=0;CAN_FilterInitStructure.CAN_FilterActivation=ENABLE;CAN_FilterInit(&CAN_FilterInitStructure);}voidCAN_init(void){NVIC_InitTypeDefNVIC_InitStructure;GPIO_InitTypeDefGPIO_InitStructure;//首先打开电源及时钟/*GPIOforCANandGPIOforLEDsclockenable*/RCC_APB2Periph
7、ClockCmd(RCC_APB2Periph_AFIOI
8、RCC_APB2Periph_GPIO_CAN,ENABLE);/*CAN1Periphclockenable*/RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1,ENABLE);/*EnableCAN1RX0interruptIRQchannel*/NVIC_InitStructure.NVIC_IRQChannel=USB_LP_CAN1_RX0_IRQn;NVIC_InitStructure.NVIC_IRQChannelPr
此文档下载收益归作者所有