AT32WB415
Series Reference Manual
2022.04.13
Page 139
Ver 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 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.
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
on the TX pin in LSB mode. The output format depends on the programmed frame format.
If synchronous transfer or clock output is selected, the clock pulse is output on the CK pin. If the hardware
flow control is selected, the control signal is input on the CTS pin.
Note: 1. The TEN bit cannot be reset during data transfer, or the data on the TX pin will be
corrupted.
2. After the TEN bit is enabled, the USART will automatically send an idle frame.
12.7.2 Transmitter configuration
1. USART enable: Set the UEN bit.
2. Full-duplex/half-duplex configuration: Refer to full-duplex/half-duplex selector for more information.
3. Mode configuration: Refer to mode selector for more information.
4. Frame format configuration: Refer to frame format for more information.
5. Interrupt configuration: Refer to interrupt generation for more information.
6. DMA transmission configuration: If the DMA mode is selected, the DMATEN bit (bit 7 in the
USART_CTRL3register) is set, and configure DMA register accordingly.
7. Baud rate configuration: Refer to baud rate generation for details.
8. Transmitter enable: When the TEN bit is set, the USART transmitter will send an idle frame.
9. Write operation: Wait unitl the TDBE bit is set, the data to be transferred will be loaded into the
USART_DT register (This operatin will clear the TDBE bit). Repeat this step in non-DMA mode.
10. After the last data expected to be transferred is written, wait until the TDC is set, indicating the end
of transfer. The USART cannot be disabled before the flag is set, or transfer error will occur.
11. When TDC=1, read access to the USART_STS register and write access to the USART_DT