GD32W51x User Manual
593
If USART_BAUD=0x21D, then INTDIV=33 (0x21), FRADIV=13 (0xD).
USARTDIV=33+13/16=33.81.
2.
Get the value of USART_BAUD by calculating the value of USARTDIV:
If USARTDIV=30.37, then INTDIV=30 (0x1E).
16*0.37=5.92, the nearest integer is 6, so FRADIV=6 (0x6).
USART_BAUD=0x1E6.
Note:
If the roundness of FRADIV is 16 (overflow), the carry must be added to the
integer part.
18.3.3.
USART transmitter
If the transmit enable bit (TEN) in USART_CTL0 register is set, when the transmit data buffer
is not empty, the transmitter shifts out the transmit data frame through the TX pin. The polarity
of the TX pin can be configured by the TINV bit in the USART_CTL1 register. Clock pulses
can output through the CK pin.
After the TEN bit is set, an idle frame will be sent. The TEN bit should not be cleared while
the transmission is ongoing.
After power on, the TBE bit is high by default. Data can be written to the USART_TDATA when
the TBE bit in the USART_STAT register is asserted. The TBE bit is cleared by writing
USART_TDATA register and it is set by hardware after the data is put into the transmit shift
register. If a data is written to the USART_TDATA register while a transmission is ongoing, it
will be firstly stored in the transmit buffer, and transferred to the transmit shift register after
the current transmission is done. If a data is written to the USART_TDATA register while no
transmission is ongoing, the TBE bit will be cleared and set soon, because the data will be
transferred to the transmit shift register immediately.
If a frame is transmitted and the TBE bit is asserted, the TC bit of the USART_STAT
register
will be set. An interrupt will be generated if the corresponding interrupt enable bit (TCIE) is
set in the USART_CTL0 register.
The USART transmit procedure is shown in
Figure 18-3. USART transmit procedure
. The
software operating process is as follows:
1.
Write the WL bit in USART_CTL0 to set the data bits length.
2.
Set the STB[1:0] bits in USART_CTL1 to configure the number of stop bits.
3.
Enable DMA (DENT bit) in USART_CTL2 if multibuffer communication is selected.
4.
Set the baud rate in USART_BAUD.
5.
Set the UEN bit in USART_CTL0 to enable the USART.
6.
Set the TEN bit in USART_CTL0.
7.
Wait for the TBE being asserted.
8.
Write the data to the USART_TDATA register.
9.
Repeat step7-8 for each data, if DMA is not enabled.
10.
Wait until TC=1 to finish.