Skip to content

Commit 438d3f1

Browse files
mrwgx3devyte
authored andcommitted
Update core_esp8266_si2c.c (#4070)
* Update core_esp8266_si2c.c Add 'clockCount' decrement, while-loop, twi_status() * Update core_esp8266_si2c.c Indents in changed function, removed superflous else
1 parent 2d39bcb commit 438d3f1

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

cores/esp8266/core_esp8266_si2c.c

+14-8
Original file line numberDiff line numberDiff line change
@@ -198,17 +198,23 @@ unsigned char twi_readFrom(unsigned char address, unsigned char* buf, unsigned i
198198
return 0;
199199
}
200200

201-
uint8_t twi_status(){
202-
if (SCL_READ()==0) return I2C_SCL_HELD_LOW; //SCL held low by another device, no procedure available to recover
201+
uint8_t twi_status() {
202+
if (SCL_READ()==0)
203+
return I2C_SCL_HELD_LOW; //SCL held low by another device, no procedure available to recover
203204
int clockCount = 20;
204205

205-
while (SDA_READ()==0 && clockCount>0){ //if SDA low, read the bits slaves have to sent to a max
206+
while (SDA_READ()==0 && clockCount>0) { //if SDA low, read the bits slaves have to sent to a max
207+
--clockCount;
206208
twi_read_bit();
207-
if (SCL_READ()==0) return I2C_SCL_HELD_LOW_AFTER_READ; //I2C bus error. SCL held low beyond slave clock stretch time
209+
if (SCL_READ()==0)
210+
return I2C_SCL_HELD_LOW_AFTER_READ; //I2C bus error. SCL held low beyond slave clock stretch time
208211
}
209212

210-
if (SDA_READ()==0) return I2C_SDA_HELD_LOW; //I2C bus error. SDA line held low by slave/another_master after n bits.
213+
if (SDA_READ()==0)
214+
return I2C_SDA_HELD_LOW; //I2C bus error. SDA line held low by slave/another_master after n bits.
211215

212-
if(!twi_write_start()) return I2C_SDA_HELD_LOW_AFTER_INIT; //line busy. SDA again held low by another device. 2nd master?
213-
else return I2C_OK; //all ok
214-
}
216+
if(!twi_write_start())
217+
return I2C_SDA_HELD_LOW_AFTER_INIT; //line busy. SDA again held low by another device. 2nd master?
218+
219+
return I2C_OK; //all ok
220+
}

0 commit comments

Comments
 (0)