C3 I2C Not Working With Some Pins - I2C_STATUS_ACK_ERROR
Posted: Tue Nov 09, 2021 12:23 am
I'm new to espressif and even i2c, so this may be just a "duh" issue...
I've got a sensor connected to my C3 and I can get it to work with some pins, but if the only thing I change in the code is the pins, then it may fail with I2C_STATUS_ACK_ERROR.
This fails with ESP_FAIL, which is actually I2C_STATUS_ACK_ERROR in esp-idf/components/driver/i2c.c:1472
Now if I change line 9: so that it uses pins "5, 8" (SDA, SCL) , it works. But if I change it to "3, 8", it also fails.
I've no idea why. For IO9, I went with the assumption that it may related to the weak pull-up esp32-c3_datasheet_en.pdf:18.
For IO3, I just figured that maybe the LED (red) that it was already tied to played some role. But when it worked with IO5 which is also already tied to an onboard LED (blue) and worked, I was at a loss.
I was aware of "ESP32-C3’s internal pull-ups are in the range of tens of kOhm, which is, in most cases, insufficient for use as I2C pull-ups." en/esp32c3/html/api-reference/peripherals/i2c.html, but figured that only applied to IO9 (and others), but didn't explain why IO5 worked and IO3 didn't.
As an aside, when it DOES work, it takes ~10 seconds for the status to get returned. But the datasheet shows it should EASILY take less than 1 second (Sensirion_Humidity_Sensors_SHT3x_Datasheet_digital.pdf:7).
I hadn't done any calculations, but I'd think 100kHz clock and only like 7 bytes would be speedy enough to not notice any lag, much less 10 seconds worth.
I've got a sensor connected to my C3 and I can get it to work with some pins, but if the only thing I change in the code is the pins, then it may fail with I2C_STATUS_ACK_ERROR.
- #include "esp_log.h"
- #include "sensirion-common.h"
- void app_main(void)
- {
- esp_err_t lEsp_err_t = ESP_OK;
- uint32_t ltryattempts = 0;
- lEsp_err_t = sensirion_i2c_init(0, 100000, 9, 8);
- if (lEsp_err_t != ESP_OK)
- ESP_LOGE(TAG, "sensirion_i2c_init failed: %s", esp_err_to_name(lEsp_err_t));
- else
- {
- uint16_t status = 0;
- do
- {
- // lEsp_err_t = sht3x_probe(SHT3X_I2C_ADDR_DFLT);
- lEsp_err_t = sensirion_i2c_delayed_read_cmd(0x44, 0xF32D, 1000, &status, 1);
- ltryattempts++;
- } while (lEsp_err_t != ESP_OK);
- if (lEsp_err_t != ESP_OK)
- ESP_LOGE(TAG, "sht3x_probe failed: %s", esp_err_to_name(lEsp_err_t));
- else
- {
- ESP_LOGI(TAG, "sht3x_probe succeeded: %s %d %d", esp_err_to_name(lEsp_err_t), ltryattempts, status);
- }
- }
Now if I change line 9:
Code: Select all
lEsp_err_t = sensirion_i2c_init(0, 100000, 9, 8);
I've no idea why. For IO9, I went with the assumption that it may related to the weak pull-up esp32-c3_datasheet_en.pdf:18.
For IO3, I just figured that maybe the LED (red) that it was already tied to played some role. But when it worked with IO5 which is also already tied to an onboard LED (blue) and worked, I was at a loss.
I was aware of "ESP32-C3’s internal pull-ups are in the range of tens of kOhm, which is, in most cases, insufficient for use as I2C pull-ups." en/esp32c3/html/api-reference/peripherals/i2c.html, but figured that only applied to IO9 (and others), but didn't explain why IO5 worked and IO3 didn't.
As an aside, when it DOES work, it takes ~10 seconds for the status to get returned. But the datasheet shows it should EASILY take less than 1 second (Sensirion_Humidity_Sensors_SHT3x_Datasheet_digital.pdf:7).
I hadn't done any calculations, but I'd think 100kHz clock and only like 7 bytes would be speedy enough to not notice any lag, much less 10 seconds worth.