Skip to content

Commit 894880b

Browse files
committed
Updating I2C to wait for STOP to be sent before returning
1 parent 6de379d commit 894880b

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/i2c.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,9 @@ where
932932
// Send a STOP condition
933933
self.i2c.cr1.modify(|_, w| w.stop().set_bit());
934934

935+
// Wait for STOP condition to transmit.
936+
while self.i2c.cr1.read().stop().bit_is_set() {}
937+
935938
// Fallthrough is success
936939
Ok(())
937940
}
@@ -965,7 +968,10 @@ where
965968
.write(|w| unsafe { w.bits((u32::from(addr) << 1) + 1) });
966969

967970
// Wait until address was sent
968-
while self.i2c.sr1.read().addr().bit_is_clear() {}
971+
while {
972+
self.check_and_clear_error_flags()?;
973+
self.i2c.sr1.read().addr().bit_is_clear()
974+
} {}
969975

970976
// Clear condition by reading SR2
971977
self.i2c.sr2.read();
@@ -983,6 +989,9 @@ where
983989
// Receive last byte
984990
*last = self.recv_byte()?;
985991

992+
// Wait for the STOP to be sent.
993+
while self.i2c.cr1.read().stop().bit_is_set() {}
994+
986995
// Fallthrough is success
987996
Ok(())
988997
} else {

0 commit comments

Comments
 (0)