I2C, NACK on ESP32 boards (SHT21 sensor) #7134
Replies: 1 comment
-
Posted at 2019-02-24 by Wilberforce A quick google shows I think this is related to clock steching by the slave which might not be implemented in the hardware version used on the esp32. Can you try the software implementation? Posted at 2019-02-24 by AkosLukacs Software I2c fails too on the ESP32. Result with soft I2c:
That Result with hardware I2C:
The Posted at 2019-02-24 by AkosLukacs Software I2C & SHT21 fails the same way on Espruino Wifi board as well. Other sensors on the same board (BMP085 and ISL29023) work with software&hardware I2C on Espruino Wifi and ESP32 without any problem with the same code. Posted at 2019-02-25 by @MaBecker
This is the Espruino software implementation of i2c, try I2C1 which is a c coded software implementation based on espressif sample and extended by clock stretching. Posted at 2019-02-25 by AkosLukacs @MaBecker good find! It works! And one more bit of info: since the "hold master" measurement failed, tried the "no hold master" way of things with my code on the ESP32. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2019-02-24 by AkosLukacs
Hi!
Edit: tested some more boards:
Tried to read an SHT21 sensor with an ESP32, but the SHT2x module did not work. Failed with CRC error, and got some console warnings about NACK by the IIC slave.
Wiring is good, there are other I2C sensors on the same board, and those works It does work. Tried the code on an Espruino wifi, and works without any problems.
After digging into the datasheet, and the "hold master" measurement failed, tried the "no hold master" way of things...
You start the conversion, and poll the sensor: the SHT21 responds with NACK while the measurement is not ready. Later managed to use the CRC check and retry reading until the sensor actually finished conversion, so I have working code on the ESP32 as well. (give me some time, and will post it)
My guess is that the STM32 and ESP32 I2C implementation differs: on STM32 it tries to read until it gets proper response with ACK from the IIC slave, and discards NACKs. On the other hand the ESP32 just returns data even when the slave said NACK.
Does anyone know whether this is true (without digging into the C source code)?
If it's true, is there some "official" guidance how to handle this in modules? The code for the ESP32 is of course bigger, so I guess it wouldn't benefit everyone to overwrite the current module.
ESP8266 - used software I2C, temperature reading fails. Hardware I2C does work. Just had some unknow problem...
Temperature reading fails with an I2C Timeout error.
Humidity measurement works. I guess the Espruino interpreter + soft I2C is slow enough that
readHumidity
does not time out before the humidity measurement is complete (22-29ms accoring to the datasheet)readTemperature
consistently times out (takes 66-85ms).But this is not the same as the ESP32, where the I2C read succeeded & ignored the NACK.
Funnily enough my ESP32 code does work, but I guess simply because the setTimeout + speed of the ESP8266 + software I2C is slow enough.
Used the hardware
I2C1
where I could:ESP32:
I2C1.setup({sda: D21, scl: D22});
I got the pins right, right? :)Espruino Wifi:
I2C1.setup({sda: B9, scl: B8});
Pixl.JS:
I2C1.setup({sda: A4, scl: A5});
ESP8266:
i2c.setup({sda: NodeMCU.D2, scl: NodeMCU.D1});
Beta Was this translation helpful? Give feedback.
All reactions