Skip to content

Commit 12bf17f

Browse files
committed
Fix Serial Write
In order to guarantee the width of the start bit in a serial transfer we need ot make sure that we are waiting for the correct amount of time. Since the timer is already started we have no guarantee of the current count value and therefore should add an initial wait.
1 parent 9c16bcd commit 12bf17f

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/serial.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ where
5858
type Error = crate::serial::Error<E>;
5959

6060
fn write(&mut self, byte: u8) -> nb::Result<(), Self::Error> {
61+
// WORKAROUND: Since we don't cancel the timer it is possible that the timer has already
62+
// overflown, in which case the first call will immediately return, with no guarantees of
63+
// being aligned with the start of the count. The second call ensures that we start the
64+
// timing at the right moment, since it will for sure block.
65+
self.wait_for_timer();
66+
self.wait_for_timer();
6167
let mut data_out = byte;
6268
self.tx.set_low().map_err(Error::Bus)?; // start bit
6369
self.wait_for_timer();

0 commit comments

Comments
 (0)