From e148ef785c328610b9400a6d6edaf5df7c9d4af0 Mon Sep 17 00:00:00 2001 From: Rutherther Date: Thu, 5 Dec 2024 16:18:37 +0100 Subject: [PATCH] feat(arm04): rounding --- arm04/src/uart.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/arm04/src/uart.c b/arm04/src/uart.c index 8b1a279..e757953 100644 --- a/arm04/src/uart.c +++ b/arm04/src/uart.c @@ -16,9 +16,14 @@ void usart_configure_speed(uart_t *uart, uint32_t clock_freq, uint32_t mantissa = temp / 16; uint32_t fraction = temp % 16; - if (fraction == 15 && ((temp + 8) % 16) == 0) { - mantissa++; - fraction = 0; + // rounding + if (((temp + 8) % 16) == 0) { + if (fraction == 15) { + mantissa++; + fraction = 0; + } else { + fraction++; + } } uart->periph->BRR = (mantissa << USART_BRR_DIV_Mantissa_Pos) | (fraction << USART_BRR_DIV_Fraction_Pos); -- 2.48.1