Tuning Fork

STM32 UART Baud Rate Divisor Exercise

Task

A serial port must send at the speed the other end listens at. That speed is the baud rate. A computer terminal uses one, a MIDI keyboard another, so firmware often reads the rate from its settings when it starts and sets the port to match.

Each test stores a different baud rate in memory before your program starts. Set USART1 to that rate, then print this line once: READY USART1's registers are on the Datasheet tab.

Circuit

Block diagram: inside U1, an STM32F4, the 16 MHz APB2 clock feeds USART1, and a settings word in SRAM, filled in before main runs, holds the rate; USART1 TX on PA9 goes to a TP1 terminal set to that rate, with a common ground

Pass condition

READY arrives, and USART1's baud rate register BRR stores the right divisor for this test's rate. BRR is what is checked. READY prints even with a wrong divisor here, though a real board would print garbage.

Expected output in every test: the program prints the one line READY after reset, at the rate in the settings word, and nothing after it

Notes

USART1 runs on a 16 MHz clock. To set its speed, you divide that clock by a number called the divisor.

Related challenges

Loading the interactive arena.