Skip to content

I2C clock stretching not implemented at all occurrences #5340

Closed
@maarten-pennings

Description

@maarten-pennings

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions