Short notes

UART Short Notes

When an STM32 sends "Hello" over USART2 to a PC terminal at 9600 baud, each character leaves PA2 as a 10-bit frame — one start bit, eight data bits, and one stop bit — with no clock line involved. UART is asynchronous, meaning both ends must agree on baud rate beforehand; even a 2% mismatch accumulates over a frame and causes framing errors by the third or fourth byte. On the STM32, USART1 is the go-to debug port because it sits on APB2 and can run at up to 4.5 Mbps.

ECE, EI

How it works

Transmission starts when software writes to the USART_DR register; the USART hardware loads the data into the shift register and pulls TX low for one bit period (start bit), then clocks out data LSB first. Baud rate is set by USART_BRR = f_clk / (16 × baud_rate) in standard mode. The receiver samples the RX line at 16× oversampling and uses a majority-vote on the middle three samples to reject noise. RXNE flag goes high when a full byte is received; TXE goes high when the transmit data register is empty and ready for the next byte.

Key points to remember

UART uses no clock line — both devices must be configured to the same baud rate (commonly 9600, 115200, or 921600 bps). A standard UART frame at 9600 baud with 8N1 format takes about 1.04 ms per byte. Parity can be odd, even, or none; 8N1 means 8 data bits, no parity, 1 stop bit. RS-232 uses ±12 V signalling while TTL UART uses 0/3.3 V or 0/5 V logic — never connect RS-232 directly to a microcontroller GPIO. Hardware flow control using RTS/CTS is added when the transmitter can outpace the receiver.

Exam tip

The examiner always asks you to calculate baud rate register value for a given clock frequency, so remember USART_BRR = f_PCLK / (16 × baud) and also know what happens when baud rates mismatch between two devices.

More Embedded Systems notes