File tree Expand file tree Collapse file tree 1 file changed +19
-1
lines changed Expand file tree Collapse file tree 1 file changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -803,7 +803,24 @@ where
803
803
. write ( |w| unsafe { w. bits ( u32:: from ( addr) << 1 ) } ) ;
804
804
805
805
// Wait until address was sent
806
- while self . i2c . sr1 . read ( ) . addr ( ) . bit_is_clear ( ) { }
806
+ while {
807
+ let sr1 = self . i2c . sr1 . read ( ) ;
808
+
809
+ // If we received a NACK, then this is an error
810
+ if sr1. af ( ) . bit_is_set ( ) {
811
+ self . i2c . sr1 . modify ( |_, w| w. af ( ) . clear_bit ( ) ) ;
812
+ return Err ( Error :: NACK ) ;
813
+ }
814
+
815
+ // Wait for the address to be acknowledged.
816
+ sr1. addr ( ) . bit_is_clear ( )
817
+ } { }
818
+
819
+ // Check for address faults (NACK received).
820
+ if self . i2c . sr1 . read ( ) . af ( ) . bit_is_set ( ) {
821
+ self . i2c . sr1 . modify ( |_, w| w. af ( ) . clear_bit ( ) ) ;
822
+ return Err ( Error :: NACK ) ;
823
+ }
807
824
808
825
// Clear condition by reading SR2
809
826
self . i2c . sr2 . read ( ) ;
@@ -830,6 +847,7 @@ where
830
847
831
848
// If we received a NACK, then this is an error
832
849
if sr1. af ( ) . bit_is_set ( ) {
850
+ self . i2c . sr1 . modify ( |_, w| w. af ( ) . clear_bit ( ) ) ;
833
851
return Err ( Error :: NACK ) ;
834
852
}
835
853
You can’t perform that action at this time.
0 commit comments