Calculate exact STM32 USART_BRR hex values with 4-bit fractional division
STM32 USART peripherals include a 12-bit integer mantissa and 4-bit fractional divider (`USART_BRR`), resolving clock division to 1/16th of a cycle. On an STM32F103 running USART1 from the 72 MHz APB2 bus, 115,200 bps maps to `USARTDIV = 39.0625`—literally an exact match (`39 + 1/16`, `BRR = 0x0271`) with 0.000% error!
Watch out for USART2/USART3 on APB1, which runs at half speed (36 MHz) on STM32F103; load the 36 MHz preset to verify its BRR register (`0x0139`) immediately.
Formulas
USARTDIV = F_PCLK ÷ (16 × Baud)BRR = (Mantissa << 4) | Fraction_4bit72 MHz / (16 × 115,200) = 39.0625 → BRR = 0x0271 (0.000% error)
Worked example
At 72 MHz and 115,200 bps, ideal divisor 39.0625 equals 39 + 1/16 exactly (`BRR = 0x0271`), yielding 115,200.0 bps and 0.000% quantization error.