From b2e81ca99e1333c61367e96bcd52fd2399216ab7 Mon Sep 17 00:00:00 2001 From: WestfW Date: Thu, 2 Aug 2018 01:07:46 -0700 Subject: [PATCH] Add rounding to Baud Rate Divisor calculation. Permits operation at 230400. regression tested at standard speeds 9600, 19200, 38400, 57600, 115200... --- cores/arduino/UARTClass.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cores/arduino/UARTClass.cpp b/cores/arduino/UARTClass.cpp index 36de1358..4952ae22 100644 --- a/cores/arduino/UARTClass.cpp +++ b/cores/arduino/UARTClass.cpp @@ -60,8 +60,8 @@ void UARTClass::init(const uint32_t dwBaudRate, const uint32_t modeReg) // Configure mode _pUart->UART_MR = modeReg; - // Configure baudrate (asynchronous, no oversampling) - _pUart->UART_BRGR = (SystemCoreClock / dwBaudRate) >> 4; + // Configure baudrate (asynchronous, no oversampling, with rounding) + _pUart->UART_BRGR = ((SystemCoreClock / dwBaudRate)+8) >> 4; // Configure interrupts _pUart->UART_IDR = 0xFFFFFFFF;