硬汉嵌入式论坛

 找回密码
 立即注册
查看: 356|回复: 0
收起左侧

STM32F4串口在8倍过采样和16倍过采样下,各种常用波特率误差和实际速度

[复制链接]

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106749
QQ
发表于 2023-11-11 00:43:04 | 显示全部楼层 |阅读模式
串口外设主频配置为84MHz。

LUA代码:


[C] 纯文本查看 复制代码
BspArray = 
{
	110,
	300,
	600,
	1200,
	2400,
	4800,
	9600,
	19200,
	38400,
	57600,
	115200,
	128000,
	230400,
	256000,
	460800,
	500000,
	512000,
	600000,
	750000,
	921600,
	1000000,
	1152000,
	1500000,
	2000000,
	2500000,
	3000000
}

Fclk = 84000000  -- 用户设置串口外设主频
OVER8 = 0       -- 0表示16过采样,1表示8倍过采样

print("所需波特率    实际值波特率    误差     BRR寄存器数值")

for i=1, #BspArray, 1 do

	Bsp = BspArray[i]

	UARRTDIV = Fclk/(8*(2-OVER8))/Bsp
	mantissa = UARRTDIV//1
	fraction = UARRTDIV - mantissa

	if(OVER8 == 0) then
		fraction_adj = (fraction*16 + 0.5)//1

		if(fraction_adj > 16) then 
		fraction_adj = 0
		mantissa = mantissa + 1
		end

		Bsp1 = Fclk/(8*(2-OVER8))/(mantissa+ fraction_adj/16)

		str = string.format("%-13d %-13.4f %7.4f%%   %-.4f = 0x%08x",
								Bsp, Bsp1, (Bsp1-Bsp)/Bsp*100, mantissa+fraction_adj/16, mantissa*16+fraction_adj)
		print(str)
	else
		fraction_adj = (fraction*8 + 0.5)//1

		if(fraction_adj > 8) then 
		fraction_adj = 0
		mantissa = mantissa + 1
		end

		Bsp1 = Fclk/(8*(2-OVER8))/(mantissa+ fraction_adj/8)

		str = string.format("%-13d %-13.4f %7.4f%%   %-.4f=0x%08x",
								Bsp, Bsp1, (Bsp1-Bsp)/Bsp*100, mantissa+fraction_adj/8, mantissa*16+fraction_adj)
		print(str)

	end
end



16过采样的误差率和实际速度如下 :

[C] 纯文本查看 复制代码
所需波特率    实际值波特率    误差     BRR寄存器数值
110           110.0001       0.0000%   47727.2500 = 0x000ba6f4
300           300.0000       0.0000%   17500.0000 = 0x000445c0
600           600.0000       0.0000%   8750.0000 = 0x000222e0
1200          1200.0000      0.0000%   4375.0000 = 0x00011170
2400          2400.0000      0.0000%   2187.5000 = 0x000088b8
4800          4800.0000      0.0000%   1093.7500 = 0x0000445c
9600          9600.0000      0.0000%   546.8750 = 0x0000222e
19200         19200.0000     0.0000%   273.4375 = 0x00001117
38400         38391.2249    -0.0229%   136.7500 = 0x0000088c
57600         57613.1687     0.0229%   91.1250 = 0x000005b2
115200        115226.3374    0.0229%   45.5625 = 0x000002d9
128000        128048.7805    0.0381%   41.0000 = 0x00000290
230400        230136.9863   -0.1142%   22.8125 = 0x0000016d
256000        256097.5610    0.0381%   20.5000 = 0x00000148
460800        461538.4615    0.1603%   11.3750 = 0x000000b6
500000        500000.0000    0.0000%   10.5000 = 0x000000a8
512000        512195.1220    0.0381%   10.2500 = 0x000000a4
600000        600000.0000    0.0000%   8.7500 = 0x0000008c
750000        750000.0000    0.0000%   7.0000 = 0x00000070
921600        923076.9231    0.1603%   5.6875 = 0x0000005b
1000000       1000000.0000   0.0000%   5.2500 = 0x00000054
1152000       1150684.9315  -0.1142%   4.5625 = 0x00000049
1500000       1500000.0000   0.0000%   3.5000 = 0x00000038
2000000       2000000.0000   0.0000%   2.6250 = 0x0000002a
2500000       2470588.2353  -1.1765%   2.1250 = 0x00000022
3000000       3000000.0000   0.0000%   1.7500 = 0x0000001c


3.png

8过采样的误差率和实际速度如下 :

[C] 纯文本查看 复制代码
所需波特率    实际值波特率    误差     BRR寄存器数值
110           110.0001       0.0000%   95454.5000=0x00174de4
300           300.0000       0.0000%   35000.0000=0x00088b80
600           600.0000       0.0000%   17500.0000=0x000445c0
1200          1200.0000      0.0000%   8750.0000=0x000222e0
2400          2400.0000      0.0000%   4375.0000=0x00011170
4800          4800.0000      0.0000%   2187.5000=0x000088b4
9600          9600.0000      0.0000%   1093.7500=0x00004456
19200         19200.0000     0.0000%   546.8750=0x00002227
38400         38391.2249    -0.0229%   273.5000=0x00001114
57600         57613.1687     0.0229%   182.2500=0x00000b62
115200        115226.3374    0.0229%   91.1250=0x000005b1
128000        128048.7805    0.0381%   82.0000=0x00000520
230400        230136.9863   -0.1142%   45.6250=0x000002d5
256000        256097.5610    0.0381%   41.0000=0x00000290
460800        461538.4615    0.1603%   22.7500=0x00000166
500000        500000.0000    0.0000%   21.0000=0x00000150
512000        512195.1220    0.0381%   20.5000=0x00000144
600000        600000.0000    0.0000%   17.5000=0x00000114
750000        750000.0000    0.0000%   14.0000=0x000000e0
921600        923076.9231    0.1603%   11.3750=0x000000b3
1000000       1000000.0000   0.0000%   10.5000=0x000000a4
1152000       1150684.9315  -0.1142%   9.1250=0x00000091
1500000       1500000.0000   0.0000%   7.0000=0x00000070
2000000       2000000.0000   0.0000%   5.2500=0x00000052
2500000       2470588.2353  -1.1765%   4.2500=0x00000042
3000000       3000000.0000   0.0000%   3.5000=0x00000034


4.png
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2024-5-4 07:28 , Processed in 0.276691 second(s), 28 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表