欢迎来到天天文库
浏览记录
ID:48621096
大小:35.51 KB
页数:5页
时间:2020-01-30
《stm32_can波特率设置指南.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、STM32的CAN波特率计算STM32里的CAN支持2.0A,2.0B,带有FIFO,中断等,这里主要提一下内部的时钟应用.bxCAN挂接在APB1总线上,采用总线时钟,所以我们需要知道APB1的总线时钟是多少.我们先看看下图,看看APB1总线时钟:APB1时钟取自AHB的分频,而AHB又取自系统时钟的分频,系统时钟可选HSI,HSE,PLLCLK,这个在例程的RC设置里都有的,然后再看看有了APB1的时钟后,如何算CAN的总线速率,先看下图:有了上边的这个图,基本就清楚了. 总线时钟MHz (3+TS1+TS2)*(BRP+1
2、)===================================================下面是我的计算:CAN_InitStructure.CAN_SJW=CAN_SJW_1tq;CAN_InitStructure.CAN_BS1=CAN_BS1_3tq;注意//#defineCAN_BS1_3tq ((uint8_t)0x02)/*!<3timequantum*/CAN_InitStructure.CAN_BS2=CAN_BS2_5tq;CAN_InitStructure.CAN_Prescaler=4;//2nominal
3、bittime(3+5+1)tq=9tq关于分频系数查看system_stm32f10x.c下面的staticvoidSetSysClockTo72(void)函数/*HCLK=SYSCLK*//*PCLK2=HCLK*//*PCLK1=HCLK/2*/所以can时钟72MHZ/2/4=9Mhztq=1/36Mhz波特率为1/nominalbittime=9/9=1MHZ=========================================----------------------------------------------- =
4、===================================================voidCAN_Configuration(void){CAN_InitTypeDef CAN_InitStructure;CAN_FilterInitTypeDef CAN_FilterInitStructure;/*CANregisterinit*/CAN_DeInit();CAN_StructInit(&CAN_InitStructure);/*CANcellinit*/CAN_InitStructure.CAN_TTCM=DISABLE;CAN_I
5、nitStructure.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_Normal;CAN_InitStructure.CAN_SJW=CAN_SJW_1tq;CAN_InitStructure.CAN_BS1=CAN_BS1_9tq;
6、CAN_InitStructure.CAN_BS2=CAN_BS2_8tq;CAN_InitStructure.CAN_Prescaler=200;CAN_Init(&CAN_InitStructure);/*CANfilterinit*/CAN_FilterInitStructure.CAN_FilterNumber=0;CAN_FilterInitStructure.CAN_FilterMode=CAN_FilterMode_IdMask;CAN_FilterInitStructure.CAN_FilterScale=CAN_FilterScale_16bit;CAN
7、_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_FilterInitStruct
此文档下载收益归作者所有