espressif / esp-idf

Espressif IoT Development Framework. Official development framework for Espressif SoCs.
Apache License 2.0
13.77k stars 7.31k forks source link

I2C Slave Clock Stretching (IDFGH-11293) #12447

Open AndreCilia opened 1 year ago

AndreCilia commented 1 year ago

Answers checklist.

General issue report

I am currently in the process of developing a smart battery application that uses SMBus as a slave device.

The workflow for communications is as follows:

  1. Master WRITES a one byte command to the Slave
  2. Slave holds the SCL line low to indicate that the data is being loaded into the buffer but its not ready yet (CLOCK STRETCHING)
  3. Slave interprets the received command and loads the data into the buffer
  4. Slave releases the SCL line to indicate that the data is now ready in the buffer
  5. Master reads out the data in the buffer

The issue at hand is that the I2C slave peripheral of the ESP32-S3 is skipping Step 2 of the above flow and since there is only random data in the buffer it sends out that.

Subsequent requests send out the previously written data.

mythbuster5 commented 1 year ago

That means you are using esp32s3 i2c as slave? not master? I don't understand your step?

AndreCilia commented 1 year ago

Yes the ESP32S3 is being used as a slave.

mythbuster5 commented 1 year ago

IMO, i2c slave clock stretching only occur in several occasions(and slave on esp32s3 doesn't support stretch in software).

AndreCilia commented 1 year ago

Hi Simon,

With your comment that "slave on ESP32s3 doesn't support stretch in software" do you mean that this is a limitation from the Espressif library?

If the Espressif library is the issue, if we re-write or modify the library ourselves would the I2C hardware be able to do clock stretching?

Thanks.

mythbuster5 commented 1 year ago

From my understanding. You want a master send a specific command, then slave do a stretch and prepare data and write into fifo. After that, release SCL bus and master reads. So, if you read esp32s3 TRM, you can see our stretch is a hardware-motivated stuff only in few occasions, rather than it can be controlled by software. So maybe this might not satisfy your requirement.

Our currently software doesn't support the stretch as well. It's more like an error handling on esp32s3.

AndreCilia commented 1 year ago

Hi Simon,

I am in contact with Espressif directly with regards to this issue. I have no idea in what state the issue is at since I am not getting any reply from who is taking care of the issue when I ask for updates.

If you can refer to ref:!00D7F0yCNM.!500A903xysz:ref please let me know whether there has been any update.

Thanks and regards, Andre

eccentricOrange commented 2 months ago

Hey @AndreCilia did you get any updates on this? I'm running into a similar problem as you, and need slave clock stretching.

AndreCilia commented 1 month ago

Hey @AndreCilia did you get any updates on this? I'm running into a similar problem as you, and need slave clock stretching.

Hi @eccentricOrange, Sorry I couldn't answer before. Espressif gave an unofficial library which works here: https://github.com/leeebo/esp_i2c_slave

eccentricOrange commented 1 month ago

Thanks a lot @AndreCilia ! This is helpful for now, though I'd really like for them to release an official solution