1
完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
本帖最后由 蓝剑威 于 2017-4-21 13:53 编辑
<转>www.cnblogs.com/shangdawei/p/4641805.html<转>www.cnblogs.com/shangdawei/p/4641805.html <转>www.cnblogs.com/shangdawei/p/4641805.html STM32 USART 波特率计算 The baud rate for the receiver and transmitter (Rx and Tx) are both set to the same value as programmed in the Mantissa and Fraction values of USARTDIV. 从上图可以看出,该寄存器高 16 位无效,最低 4 位为小数部分,其余部分为整数部分。 这样的设计可以使波特率更加精确。关于波特率的产生,有这么一段话来解释: 分数波特率的产生: 接收器和发送器(RX和TX)都是设置成为 USARTDIV 整数和小数寄存器中配置的值。 This give the following equation for baud rate: Tx/Rx baud = CK_APB1 / (8 x (2 - OVER8) x USARTDIV) Where USARTDIV is an unsigned fixed point number that is coded on the USART_BRR register.
The baud counters are updated to the new value in the baud registers after a write operation to USART_BRR. Hence the baud rate register value should not be changed during communication. The USARTs are on the APB1 bus, Figure 12 in the reference manual is the clock tree, which shows how the APB1 clock is derived from the PLL clock. The maximum APB1 clock is 32MHz. OVER8=1 is required for higher speeds, giving: baud = 32000000 / (USARTDIV x 8). So USARTDIV = 32000000 / (baud x 8) For 4Mbps therefore, USARTDIV=1 (see table 138 S.No.12 for details). For 2Mps, USARTDIV=2. To achieve 3Mbps you will have to reduce the APB1 clock to 24MHz and set USARTDIV=1 (see table 131). But note that the clock rate changes for all other APB1 peripherals too. The simplest way to correctly program the USART baud rate is via the STM32L1xx standard peripheral library. Also to determine the correct peripheral clock settings (and more), and generate initialisation code, you can use STM's MicroXplorer tool. Fpclk = 12 MHz, Baud = 460800 Bps : OVER8 = 0 DIV = 12000000 / ( 16 * 460800 ) = 1.6276 DIV_Mantissa = 1 DIV_Fraction = 0.6276 * 16 = 10 USARTDIV = ( 1 << 4 ) | 10 = 0x001 A = 1.625 12000000 / ( 16 * 1.625 ) = 12000000 / 26 = 461538.5 Bps Fpclk = 12 MHz, Baud = 460800 Bps : OVER8 = 1 DIV = 12000000 / ( 8 * 460800 ) = 3.255 DIV_Mantissa = 3 DIV_Fraction = 0.255 * 8 = 2.04 USARTDIV = ( 3 << 4 ) | 2 = 0x003 2 = 3.25 12000000 / ( 8 * 3.25 ) = 12000000 / 26 = 461538.5 Bps STM32波特率设置,在115200时候,实际是115384,会有0.15%的误差, 不过还是可以接受的。 其实stm32的uart还是蛮简单的,初始化4个寄存器完事,就是波特率方面需要算算。 原文: stm32 中文资料中有如下计算公式 : Tx / Rx 波特率 = fPCLKx/(16*USARTDIV); 这里的fPCLKx(x=1、2)是给外设的时钟(PCLK1用于USART2、3、4、5,PCLK2用于USART1) USARTDIV是一个无符号的定点数。这12位的值设置在USART_BRR寄存器。 如果使用USART1,系统时钟为72MHZ,USART1使用PCLK2时钟,也定义为72MHz. 定义波特率=9600,fPCLK2=72MHz,则: 计算USARTDIV=72MHz/9600/16=468.75 取整数468=0x1D4. 小数0.75*16=12=0x0C. 所以写入寄存器USART_BRR中的值为:USART_BRR=0x1D4C. 如果使用USART2,USART2使用PCLK1时钟,PCLK1时钟为36MHz. 定义波特率=9600,fPCLK1=36MHz,则: 计算USARTDIV=36MHz/9600/16=234.375 取整数234=0xEA.小数0.375*16=6=0x06.所以写入寄存器USART_BRR中的值为:USART_BRR=0xEA6. |
|
相关推荐
|
|
1146 浏览 0 评论
飞凌嵌入式ElfBoard ELF 1板卡-mfgtools烧录流程介绍之烧写所需镜像
1225 浏览 0 评论
飞凌嵌入式ElfBoard ELF 1板卡-mfgtools烧录流程之烧写方法
675 浏览 0 评论
飞凌嵌入式ElfBoard ELF 1板卡-内核编译之初次编译
1019 浏览 0 评论
飞凌嵌入式ElfBoard ELF 1板卡-内核源代码的目录结构和文件说明
937 浏览 0 评论
小黑屋| 手机版| Archiver| 德赢Vwin官网 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-23 18:56 , Processed in 0.454955 second(s), Total 37, Slave 30 queries .
Powered by 德赢Vwin官网 网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
德赢Vwin官网 观察
版权所有 © 湖南华秋数字科技有限公司
德赢Vwin官网 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号