1 character send/receive application [USART of STM32]

This is the simplest program for STM32 USART. The communication application is almost language-like outside of MCU knowledge because it deals with strings. It is a great way to familiarize yourself with arrays to store characters, the concept of pointers and addresses, etc.

Let's start with a program that sends and receives a single character (1 byte) serially.

Setting Spec. :
Input   : PC10 Floating input
Output :PC11 Alternate Push-pull output

Serial connection diagram

Insert delay_ms(100) in the main function to make it a 100 ms cycle infinite loop.

Whether a character is input or not is checked by polling the flag USART_FLAG_RXNE of USART_GetFlagStatus() every 100ms.

When a reception is received, USART_ReceiveData() stores one character in the variable RxData.

The character stored in the variable RxData is sent by USART_SendData(). This communication is called echo back. The same character continues to be displayed every cycle (100ms) until the next character is received.


Transmitted characters from MCU are displayed in serial communication by an application called terminal software (terminal emulator) on the PC side. Set the communication conditions to be the same as those of MCU. Common terminal software includes Tera Term.


 Serial communication conditions: 

  • Baud Rate: 9600
  • Data lentgh: 8 bits
  • Stopbit: 1
  • Parity: None
  • Flow control: None

Follow me!