diff --git a/hardware0.hpp b/hardware0.hpp index 5a054b5..5c5c606 100644 --- a/hardware0.hpp +++ b/hardware0.hpp @@ -55,7 +55,9 @@ struct HardwareAbstraction { template static constexpr auto calcBaud() { - return static_cast((F_CPU / (16 * baudRate)) - 1); + // The actual formula is (F_CPU / (16 * baudRate)) - 1, but this one has the advantage of rounding correctly + constexpr auto baudVal = (F_CPU + 8 * baudRate) / (16 * baudRate) - 1; + return baudVal; } struct DataBitsVal {