Skip to content

Commit

Permalink
generic: serial: Fix U2Xn not being reset
Browse files Browse the repository at this point in the history
Some Arduino firmware versions set the U2Xn bit which leads to doubled
baudrate as avr-hal currently does not ensure the bit is reset to zero
on initialization.  Fix this by resetting the UCSRnA register entirely.

Signed-off-by: Rahix <rahix@rahix.de>
  • Loading branch information
Rahix committed Sep 1, 2020
1 parent 0f549e0 commit 7caed3a
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions avr-hal-generic/src/serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ macro_rules! impl_usart {
let brr = CLOCK::FREQ / (16 * baud) - 1;
self.p.[<ubrr $n>].write(|w| unsafe { w.bits(brr as u16) });

self.p.[<ucsr $n a>].reset();

// Enable receiver and transmitter but leave interrupts disabled.
self.p.[<ucsr $n b>].write(|w| w
.[<txen $n>]().set_bit()
Expand Down

0 comments on commit 7caed3a

Please sign in to comment.