From 0643238eca365bbd84c73c74f9db5fd8b855e8d1 Mon Sep 17 00:00:00 2001 From: mrwgx3 <23343823+mrwgx3@users.noreply.github.com> Date: Tue, 2 Jan 2018 05:22:45 -0700 Subject: [PATCH 1/2] Update core_esp8266_si2c.c Add 'clockCount' decrement, while-loop, twi_status() --- cores/esp8266/core_esp8266_si2c.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/cores/esp8266/core_esp8266_si2c.c b/cores/esp8266/core_esp8266_si2c.c index bb8e619eee..d8312a9876 100644 --- a/cores/esp8266/core_esp8266_si2c.c +++ b/cores/esp8266/core_esp8266_si2c.c @@ -198,17 +198,18 @@ 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 (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 -} \ No newline at end of file + else return I2C_OK; //all ok +} From d8d18e5a6f7bdb9eeb29cbab74862567843628e2 Mon Sep 17 00:00:00 2001 From: Develo Date: Fri, 23 Mar 2018 15:38:11 -0300 Subject: [PATCH 2/2] Update core_esp8266_si2c.c Indents in changed function, removed superflous else --- cores/esp8266/core_esp8266_si2c.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/cores/esp8266/core_esp8266_si2c.c b/cores/esp8266/core_esp8266_si2c.c index d8312a9876..3aba06fe16 100644 --- a/cores/esp8266/core_esp8266_si2c.c +++ b/cores/esp8266/core_esp8266_si2c.c @@ -199,17 +199,22 @@ unsigned char twi_readFrom(unsigned char address, unsigned char* buf, unsigned i } uint8_t twi_status() { - if (SCL_READ()==0) return I2C_SCL_HELD_LOW; //SCL held low by another device, no procedure available to recover + 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 --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 }