Skip to content

Commit 8ae0746

Browse files
authored
Add missing decrement operator to I2C clockCount (#5292)
1 parent 8785143 commit 8ae0746

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

Diff for: cores/esp8266/core_esp8266_si2c.c

+9-10
Original file line numberDiff line numberDiff line change
@@ -293,24 +293,23 @@ unsigned char twi_readFrom(unsigned char address, unsigned char* buf, unsigned i
293293
}
294294

295295
uint8_t twi_status() {
296-
if (SCL_READ()==0) {
296+
if (SCL_READ() == 0)
297297
return I2C_SCL_HELD_LOW; // SCL held low by another device, no procedure available to recover
298-
}
298+
299299
int clockCount = 20;
300-
while (SDA_READ()==0 && clockCount>0) { // if SDA low, read the bits slaves have to sent to a max
300+
while (SDA_READ() == 0 && clockCount-- > 0) { // if SDA low, read the bits slaves have to sent to a max
301301
twi_read_bit();
302-
if (SCL_READ()==0) {
302+
if (SCL_READ() == 0) {
303303
return I2C_SCL_HELD_LOW_AFTER_READ; // I2C bus error. SCL held low beyond slave clock stretch time
304304
}
305305
}
306-
if (SDA_READ()==0) {
306+
if (SDA_READ() == 0)
307307
return I2C_SDA_HELD_LOW; // I2C bus error. SDA line held low by slave/another_master after n bits.
308-
}
309-
if (!twi_write_start()) {
308+
309+
if (!twi_write_start())
310310
return I2C_SDA_HELD_LOW_AFTER_INIT; // line busy. SDA again held low by another device. 2nd master?
311-
} else {
312-
return I2C_OK;
313-
}
311+
312+
return I2C_OK;
314313
}
315314

316315
uint8_t twi_transmit(const uint8_t* data, uint8_t length)

0 commit comments

Comments
 (0)