
AT32F413
Series Reference Manual
2022.06.27
Page 148
Rev 2.00
12.6 Baud rate generation
12.6.1 Introduction
USART baud rate generator uses an internal counter based on PCLK. The DIV (USART_BAUDR [15:0]
register) represents the overflow value of the counter. Each time the counter is full, it denotes one-bit
data. Thus each data bit width refers to PCLK cycles x DIV.
The receiver and transmitter of USART share the same baud rate generator, and the receiver splits each
data bit into 16 equal parts to achieve oversampling, so the data bit width should not be less than 16
PCLK periods, that is, the DIV value must be equal to or be greater than 16.
12.6.2 Configuration
User can program the desired baud rate by setting different system clocks and writing different values
into the USART_BAUDR register. The calculation format is as follows:
TX
RX
𝑏𝑎𝑢𝑑 𝑟𝑎𝑡𝑒 =
𝑓
𝐶𝐾
DIV
Where,
𝑓
𝐶𝐾
refers to the system clock of USART (i.e. PCLK1/PCLK2 )
Note: 1.
Write access to the USART_BAUDR register before UEN. The baud rate register value should
not be altered when UEN=1.
2. When USART receiver or transmitter is disabled, the internal counter will be reset, and baud rate
interrupt will occur.
Table 12-1 Error calculation for programmed baud rate
Baud
fPCLK=36MHz
fPCLK=72MHz
No.
Kbps
Actual
Value programmed in
the baud register
Error% Actual
Value programmed in
the baud register
Error%
1
2.4
2.4
15000
0%
2.4
30000
0%
2
9.6
9.6
3750
0%
9.6
7500
0%
3
19.2
19.2
1875
0%
19.2
3750
0%
4
57.6
57.6
625
0%
57.6
1250
0%
5
115.2
115.384
312
0.15
%
115.2
625
0%
6
230.4
230.769
156
0.16
%
230.769
312
0.16
%
7
460.8
461.538
78
0.16
%
461.538
156
0.16
%
8
921.6
923.076
39
0.16
%
923.076
78
0.16
%
9
2250
2250
16
0%
2250
32
0%
10
4500
N
A
NA
N
A
4500
16
0%
Taking a baud rate of 115.2Kbps as an example, if fPCLK=36MHz, the value in the baud register should be
set to 312(0x38). Based on formula, the calculated baud rate (acutal) is 36000000 / 312 = 115384 =
115.384Kbps. The % error between the desired and actual value is calculated based on the formula:
(Calculated actual result-Desired)/desired baud rate*100%, that is, (115.384 - 115.2) / 115.2 * 100% = 0.15%.
12.7 Transmitter
12.7.1 Transmitter introduction
USART transmitter has its individual TEN control bit. The transmitter and receiver share the same baud
rate that is programmable. There is a transmit data buffer (TDR) and a transmit shift register in the
USART. The TDBE bit is set whenever the TDR is empty, and an interrupt is generated if the TDBEIEN
is set.
The data written by software is stored in the TDR register. When the shift register is empty, the data will
be moved from the TDR register to the shift register so that the data in the transmit shift register is output