![Geehy SEMICONDUCTOR APM32F405 Series User Manual Download Page 319](http://html1.mh-extra.com/html/geehy-semiconductor/apm32f405-series/apm32f405-series_user-manual_573630319.webp)
www.geehy.com Page 318
Decide the word length by setting DBLCFG bit of USART_CTRL1
register.
Decide the number of stop bits by setting STOPCFG bit of
USART_CTRL2 register.
If multi-buffer communication is selected, DMA should be enabled in
USART_CTRL3 register.
Set the baud rate of communication in USART_BR register.
Enable TXEN bit in USART_CTRL1 register, and transmit an idle
frame.
Wait for TXBEFLG bit of USART_STS register to be set to 1.
Write data to USART_DATA register (if DMA is not enabled, repeat
steps 7-8 for each byte to be sent).
Wait for TXCFLG bit of USART_STS register to be set to 1, indicating
transmission completion.
Note: TXEN bit cannot be reset during data transmission; otherwise, the data on TX pin will be
destroyed, which is because if the baud rate generator stops counting, the data being transmitted will be
lost.
Single-byte communication
TXBEFLG bit can be cleared by writing USART_DATA register. When the
TXBEFLG bit is set by hardware, the shift register will receive the data
transferred from the data transmit register, then the data will be transmitted, and
the data transmit register will be cleared. The next data can be written in the
data register without covering the previous data.
If TXBEIEN in USART_CTRL1 register is set to 1, an interrupt will be
generated.
If USART is in the state of transmitting data, write to the data register to
save the data to the DATA register, and transfer the data to the shift
register at the end of the current data transmission.
If USART is in idle state, write to the data register, put the data into the
shift register, start transmitting data, and set TXBEFLG bit to 1.
When a data transmission is completed and TXBEFLG bit is set,
TXCFLG bit will be set to 1; at this time if TXCIEN bit in USART_CTRL1
register is set to 1, an interrupt will be generated.
After the last data is written in the USART_DATA register, before
entering the low-power mode or before closing the USART module, wait
to set TXCFLG to 1.
Break frame
The break frames are considered to receive 0 in a frame period. Setting TXBF
bit of USART_CTRL1 register can transmit a break frame, and the length of the
break frame is determined by DBLCFG bit of USART_CTRL1 register. If the