Skip to content

ESP32-S2 I2C does not honor repeated-start (no stop) in API? #4729

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

Closed
ladyada opened this issue Jan 18, 2021 · 12 comments · Fixed by #5683
Closed

ESP32-S2 I2C does not honor repeated-start (no stop) in API? #4729

ladyada opened this issue Jan 18, 2021 · 12 comments · Fixed by #5683
Assignees
Milestone

Comments

@ladyada
Copy link
Contributor

ladyada commented Jan 18, 2021

hey @me-no-dev i verified someone trying an ESP32-S2 with an lc709203f and i am pretty sure that the issue is that when we ask for no-stop in uint8_t TwoWire::endTransmission(bool sendStop) its sending a stop anyways.

This is the correct I2C transaction to read the ID code (on avr chipset)
image
we write 0x11 register command to i2c device 0xB, don't stop, then read 3 bytes of data

if we run the same code on ESP32-S2 I get:
image
(there's a delay due to serial printf)
with wrong data 0xFF

if we go back to avr and turn ON stop (which is incorrect), we get the same resulting trace:
image
same wrong data

this could be the root cause for
#4589
#4561
#4375
#4403

those are also repeated-start devices. not all i2c devices require repeated start

@me-no-dev
Copy link
Member

@ladyada sorry for the delay. I2C for S2 uses ESP-IDF's I2C driver. I did not find a way to ensure no-stop there and remember that in order for that to work, write and read need to happen in one bus transaction (not really Arduino-friendly and with possible multitasking issues). Unfortunately we have not heard from @stickbreaker in a loong time (he was maintaining the driver) but we are looking into getting some help internally to be able to handle that in near future.

@ladyada
Copy link
Contributor Author

ladyada commented Jan 27, 2021

hihi thanks for replying - there's quite a few chips that require write-then-read in one no-stop transaction. we haven't heard of this problem before for ESP32 (just S2) so it could be a regression in v4.2 or for S2

either way its OK if there's a separate call just for write-then-read added, we have abstracted away the API for all our sensors so we could easily add that exception - just let me know :)

@erichiller
Copy link

Is there a surround workaround for this? Perhaps @ladyada you know of one?
I'm encountering this with:

  • Adafruit ESP32-S2 Metro
  • Adafruit MLX90640 (55°)

@ladyada
Copy link
Contributor Author

ladyada commented Jun 9, 2021

there is no work-around, it must be fixed here/IDF :)

@me-no-dev
Copy link
Member

we are aware of the issue, it will be fixed before 2.0.0 is released :)

@ladyada
Copy link
Contributor Author

ladyada commented Jun 10, 2021

awesome thank you @me-no-dev :)

@VojtechBartoska
Copy link
Contributor

VojtechBartoska commented Jun 24, 2021

This issue will be solved internally in ESP-IDF IDF-3460

@hallard
Copy link
Contributor

hallard commented Jul 5, 2021

ahah Just came up here after scratching my head for 2 hours trying to have battery monitoring on Metro ESP32 S2. Glad to see it's not on our side. Just let us know if there is a fixed branch to test before official release of 2.0.0

@SuGlider
Copy link
Collaborator

@ladyada , I just submitted a PR #5664 that shall fix the issue you reported.
Could you please apply it to your environment and verify if it solves this issue?

Thanks!

@ladyada
Copy link
Contributor Author

ladyada commented Sep 14, 2021

@SuGlider LC709 works right now, so it seems to have solved at least that issue!

@me-no-dev
Copy link
Member

Hi @ladyada could you please re-test with this new PR: #5683
I have only MLX90614 as sensor that requires repeated start and that worked without issues.

@nseidle
Copy link

nseidle commented Oct 11, 2021

I can confirm #5683 fixes the repeated start problem. Below is original bad recorded on ESP32-S2 w/ MLX90640:
image

Now with #5683 changes:
image

Sensor is happily reporting. Thanks @me-no-dev!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
7 participants