Closed
Description
When using as I2C slave the CCS811 gas sensor from ams, e.g. using this board, there are communication errors. These are due to the CCS811 doing clock stretching.
The driver file core_esp8266_si2c.c "Software I2C library for esp8266" implements clock stretching. However, at two places clock stretching code is missing. Functions twi_writeTo()
and twi_readFrom()
set the clock line high using SCL_HIGH()
, without checking whether SCL really goes high. All other places in the driver that use SCL_HIGH()
do have the clock stretch check.
In both functions, one line should be added (here and here):
while(SDA_READ() == 0 && (i++) < 10){
SCL_LOW();
twi_delay(twi_dcount);
SCL_HIGH();
unsigned int t=0; while(SCL_READ()==0 && (t++)<twi_clockStretchLimit); // Clock stretching
twi_delay(twi_dcount);
}
See this screenshot for a diff.