Skip to content

Update core_esp8266_si2c.c #4070

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Mar 24, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions cores/esp8266/core_esp8266_si2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,17 +198,23 @@ unsigned char twi_readFrom(unsigned char address, unsigned char* buf, unsigned i
return 0;
}

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

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

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

if(!twi_write_start()) return I2C_SDA_HELD_LOW_AFTER_INIT; //line busy. SDA again held low by another device. 2nd master?
else return I2C_OK; //all ok
}
if(!twi_write_start())
return I2C_SDA_HELD_LOW_AFTER_INIT; //line busy. SDA again held low by another device. 2nd master?

return I2C_OK; //all ok
}