波特率配置
通过配置寄存器UART_IBRD 和UART_FBRD 可以设置UART 工作的波特率,波特率
计算公式为:
当前波特率=UART 参考时钟频率(1/2 总线时钟频率)/(16 x 分频系数)
分频系数有整数和小数两部分组成,分别对应寄存器UART_IBRD 和UART_FBRD。
例如:UART 参考时钟频率为60MHz,如果配置UART_IBRD 为0x1E,UART_FBRD
为0x00,按照波特率计算公式,则当前的波特率为60/(16 x 30)=0.125Mbit/s。
UART 波特率配置的典型值为:9,600bit/s、14,400bit/s、19,200bit/s、38,400bit/s、
57,600bit/s、76,800bit/s、115,200bit/s、230,400bit/s、460,800bit/s。
分频系数值的计算以及分频系数寄存器的配置举例如下:
如果要求波特率为230400bit/s,并且UART 参考时钟频率为100MHz,那么分频系数
为(100 x 106)/(16 x 230400)=27.1267,因此IBRD(整数部分)为27,FBRD(小
数部分)为0.1267。
计算6bit UART_FBRD 寄存器中的数值:根据m=integer(FBRDx2n+0.5)
(n=UART_FBRD 寄存器的宽度),计算出m=integer(0.1267x26+0.5)=8,在
UART_IBRD 寄存器中配置0x001B,UART_FBRD 寄存器中配置0x08。
当分频系数小数部分配置成8 时,波特率除数的实际数值为27+8/64=27.125,产生的
波特率为(100 x 106)/(16 x 27.125)=230414.75,误差率为(230414.75–230400)
/230400x100=0.006%。
使用6bit UART_FBRD 寄存器最大的误差率为1/64 x 100=1.56%,当m=1 时会出现,
误差率累计超过64 个时钟周期。
相关文章









