C3 I2C Not Working With Some Pins - I2C_STATUS_ACK_ERROR

vindicator
Posts: 3
Joined: Mon Nov 08, 2021 11:37 pm

C3 I2C Not Working With Some Pins - I2C_STATUS_ACK_ERROR

Postby vindicator » 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.
  1. #include "esp_log.h"
  2. #include "sensirion-common.h"
  3.  
  4. void app_main(void)
  5. {
  6.     esp_err_t lEsp_err_t = ESP_OK;
  7.     uint32_t ltryattempts = 0;
  8.  
  9.     lEsp_err_t = sensirion_i2c_init(0, 100000, 9, 8);
  10.     if (lEsp_err_t != ESP_OK)
  11.         ESP_LOGE(TAG, "sensirion_i2c_init failed: %s", esp_err_to_name(lEsp_err_t));
  12.  
  13.     else
  14.     {
  15.         uint16_t status = 0;
  16.         do
  17.         {
  18.             // lEsp_err_t = sht3x_probe(SHT3X_I2C_ADDR_DFLT);
  19.             lEsp_err_t = sensirion_i2c_delayed_read_cmd(0x44, 0xF32D, 1000, &status, 1);
  20.             ltryattempts++;
  21.         } while (lEsp_err_t != ESP_OK);
  22.  
  23.         if (lEsp_err_t != ESP_OK)
  24.             ESP_LOGE(TAG, "sht3x_probe failed: %s", esp_err_to_name(lEsp_err_t));
  25.  
  26.         else
  27.         {
  28.             ESP_LOGI(TAG, "sht3x_probe succeeded: %s %d %d", esp_err_to_name(lEsp_err_t), ltryattempts, status);
  29.         }
  30. }
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:

Code: Select all

lEsp_err_t = sensirion_i2c_init(0, 100000, 9, 8);
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.

ESP_Sprite
Posts: 9749
Joined: Thu Nov 26, 2015 4:08 am

Re: C3 I2C Not Working With Some Pins - I2C_STATUS_ACK_ERROR

Postby ESP_Sprite » Tue Nov 09, 2021 1:45 am

No, the internal pullup on all GPIOs is the same and you need an external pullup for I2C to work properly. Without those pullups, you can get random behaviour like this.

vindicator
Posts: 3
Joined: Mon Nov 08, 2021 11:37 pm

Re: C3 I2C Not Working With Some Pins - I2C_STATUS_ACK_ERROR

Postby vindicator » Tue Nov 09, 2021 3:29 am

Okay, so it seems the module already contained everything needed (caps / 10k resistors which coincides with the Sensirion_Humidity_Sensors_SHT3x_Datasheet_digital.pdf:8) "SHT31 SHT31-D Temperature & Humidity Sensor Breakout Weather For Arduino https://www.ebay.com/itm/112375172555?h ... SwQJlfy0LL" (looks just like what I got).
My old blind eyes could barely make out the "103" on the smd.

I changed .scl_pullup_en and .sda_pullup_en = GPIO_PULLUP_DISABLE, but the same effect is happening: SDA=IO3 fails; I05 works.

EDIT0: GPIO_PULLDOWN_DISABLE -> GPIO_PULLUP_DISABLE
Last edited by vindicator on Tue Nov 09, 2021 6:28 am, edited 1 time in total.

Who is online

Users browsing this forum: benrank and 129 guests