File tree Expand file tree Collapse file tree 1 file changed +9
-10
lines changed Expand file tree Collapse file tree 1 file changed +9
-10
lines changed Original file line number Diff line number Diff line change @@ -145,22 +145,20 @@ int I2C::recover(PinName sda, PinName scl)
145
145
DigitalInOut pin_sda (sda, PIN_INPUT, PullNone, 1 );
146
146
DigitalInOut pin_scl (scl, PIN_INPUT, PullNone, 1 );
147
147
148
- // Read and verify if recovery is required
149
- if (pin_scl == 1 ) {
150
- if (pin_sda == 1 ) {
151
- // Return successfuly as SDA and SCL is high
152
- return 0 ;
153
- }
154
- } else {
155
- // Return as SCL is low and no access to become master.
148
+ // Return as SCL is low and no access to become master.
149
+ if (pin_scl == 0 ) {
156
150
return I2C_ERROR_BUS_BUSY;
157
151
}
158
152
153
+ // Return successfully as SDA and SCL is high
154
+ if (pin_sda == 1 ) {
155
+ return 0 ;
156
+ }
157
+
159
158
// Send clock pulses, for device to recover 9
160
159
pin_scl.mode (PullNone);
161
160
pin_scl.output ();
162
- int count = 9 ;
163
- while (count--) {
161
+ for (int count = 0 ; count < 10 ; count++) {
164
162
pin_scl.mode (PullNone);
165
163
pin_scl = 0 ;
166
164
wait_us (5 );
@@ -184,6 +182,7 @@ int I2C::recover(PinName sda, PinName scl)
184
182
// Return as SCL is low and no access to become master.
185
183
return I2C_ERROR_BUS_BUSY;
186
184
}
185
+
187
186
return 0 ;
188
187
}
189
188
You can’t perform that action at this time.
0 commit comments