Open tangiblewaves opened 1 week ago
Are you using setup() and loop() or just a main()
or can you show a minimal sketch that just demonstrates your problem?
I'm using setup() and loop(); good old Arduino style ;.)
Im setup(), I'm calling
_PROTECTED_WRITE(CLKCTRL.MCLKCTRLB, CLKCTRL_PDIV_2X_gc | CLKCTRL_PEN_bm);
Later in setup() then
Serial0.begin(MIDI_BAUDRATE);
I fix it by calling
USART0.BAUD = ....
after Serial0.begin(...)
Really, not a big issue, but in case somebody stumbles upon the same problem...
Thanks!
I came across this issue: I used Serial0 (baudrate does not matter here) and found, that the effective baudrate was wrong after Serial0.begin(). Looking into the source of UART.cpp I saw that the baudrate divider is calculated as
baud_setting = (((4 * F_CPU) / baud))
which is fine for the default value of the Periperal clock (PDIV in CLKCTRL.MCLKCTRLB). But I had changed this; therefore the calculation failed. Was no issue to workaraund, just by setting USART.BAUD after Serial0.begin(), but I wonder, if the peripheral clock should be considered in the baudrate calculation?