Fixed rounding error in baud rate calculation
This commit is contained in:
parent
00cb9ad13c
commit
6ded0e1c8d
@ -55,7 +55,9 @@ struct HardwareAbstraction<SupportedHardware::ATmega1284P> {
|
|||||||
template <uint32_t baudRate>
|
template <uint32_t baudRate>
|
||||||
static constexpr auto calcBaud()
|
static constexpr auto calcBaud()
|
||||||
{
|
{
|
||||||
return static_cast<uint16_t>((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 {
|
struct DataBitsVal {
|
||||||
|
Loading…
Reference in New Issue
Block a user