File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -840,10 +840,15 @@ where
840
840
self . i2c . cr1 . modify ( |_, w| w. start ( ) . set_bit ( ) ) ;
841
841
842
842
// Wait until START condition was generated
843
- while self . i2c . sr1 . read ( ) . sb ( ) . bit_is_clear ( ) { }
843
+ while {
844
+ self . check_and_clear_error_flags ( ) ?;
845
+ self . i2c . sr1 . read ( ) . sb ( ) . bit_is_clear ( )
846
+ } { }
844
847
845
848
// Also wait until signalled we're master and everything is waiting for us
846
849
while {
850
+ self . check_and_clear_error_flags ( ) ?;
851
+
847
852
let sr2 = self . i2c . sr2 . read ( ) ;
848
853
sr2. msl ( ) . bit_is_clear ( ) && sr2. busy ( ) . bit_is_clear ( )
849
854
} { }
@@ -876,7 +881,12 @@ where
876
881
877
882
fn send_byte ( & self , byte : u8 ) -> Result < ( ) , Error > {
878
883
// Wait until we're ready for sending
879
- while self . i2c . sr1 . read ( ) . tx_e ( ) . bit_is_clear ( ) { }
884
+ while {
885
+ // Check for any I2C errors. If a NACK occurs, the ADDR bit will never be set.
886
+ self . check_and_clear_error_flags ( ) ?;
887
+
888
+ self . i2c . sr1 . read ( ) . tx_e ( ) . bit_is_clear ( )
889
+ } { }
880
890
881
891
// Push out a byte of data
882
892
self . i2c . dr . write ( |w| unsafe { w. bits ( u32:: from ( byte) ) } ) ;
You can’t perform that action at this time.
0 commit comments