Various Methods for Sending Strings via STM32 UART

Various Methods for Sending Strings via STM32 UART

Using USART to send strings with STM32:

Various Methods for Sending Strings via STM32 UARTVarious Methods for Sending Strings via STM32 UARTVarious Methods for Sending Strings via STM32 UARTVarious Methods for Sending Strings via STM32 UART

The meaning of the code is:

When there is data on the receive pin, the status register USART_FLAG_RXNE will be set to 1. At this point, the return value of USART_GetFlagStatus(USART1, USART_FLAG_RXNE) will be 1 (SET), and if there is no data, it will be RESET.

Common code writing methods and their data reception effects:

Method 1:

Various Methods for Sending Strings via STM32 UARTVarious Methods for Sending Strings via STM32 UART

This method works well under normal conditions (not in special situations such as power-off or standby), and the USART data will be successfully sent. However, in the aforementioned special situations, the issue arises where the code only places the data in the send buffer without actually sending it before power-off or standby, resulting in the last two characters not being sent.

Method 2:

Various Methods for Sending Strings via STM32 UARTVarious Methods for Sending Strings via STM32 UART

The difference with this method is that the second-to-last data is sent, meaning only the last character is not sent.

Method 3:

Various Methods for Sending Strings via STM32 UARTVarious Methods for Sending Strings via STM32 UART

This method results in sending 10 characters.

Method 4:

Various Methods for Sending Strings via STM32 UARTVarious Methods for Sending Strings via STM32 UART

This method should theoretically achieve the function, but in practice, multiple tests have shown that the first byte of data is lost.

Method 5:

Various Methods for Sending Strings via STM32 UARTVarious Methods for Sending Strings via STM32 UART

This method is relatively complete, and to be conservative, it is recommended to use this method in special situations.

Various Methods for Sending Strings via STM32 UART

Various Methods for Sending Strings via STM32 UART

Screenshots from some electronic books

Various Methods for Sending Strings via STM32 UART

【Complete Set of Hardware Learning Materials Collection】

Various Methods for Sending Strings via STM32 UART

Leave a Comment