Skip to content
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

I2C communication failures on ESP32-S3 (works on ESP32) (IDFGH-7138) #8741

Open
CSHaze opened this issue Apr 7, 2022 · 21 comments
Open

I2C communication failures on ESP32-S3 (works on ESP32) (IDFGH-7138) #8741

CSHaze opened this issue Apr 7, 2022 · 21 comments
Assignees
Labels
Status: Opened Issue is new

Comments

@CSHaze
Copy link

CSHaze commented Apr 7, 2022

Environment

  • Development Kit: ESP32-S3-DevKitC-1
  • Kit version DevKitC: v1
  • Module or chip used: ESP32-S3-WROOM-1
  • IDF version: v4.4
  • Build System: idf.py
  • Compiler version: (crosstool-NG esp-2021r2-patch2) 8.4.0
  • Operating System: Windows
  • (Windows only) environment type: ESP Command Prompt
  • Using an IDE?: Yes, VSCode ESP-IDF extension
  • Power Supply: USB

Problem Description

I2C device communication that works on the standard ESP32 does not work on the ESP32-s3.

Expected Behavior

I would expect I2C functionality to work similarly on both devices.

Actual Behavior

I2C writes work correctly on the standard ESP32 but do not work on the ESP32-s3.

Steps to reproduce

  1. Attach an I2C device (I am using an HTU21d)
  2. Run the scan program on a standard ESP32 (https://github.com/UncleRus/esp-idf-i2cscan)
  3. Observe the scan shows the correct output.
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: 40 -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
  1. Run the scan program on an ESP32-s3
  2. Observe the scan does not find the device
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

Note: I have tried other libraries, communication calls, and configurations (pullups, clk freq, gpio, etc) through IC2, all of which are unable to write to the device. I figured this was the simplest example.

Code to reproduce this issue

#include <driver/i2c.h>
#include <esp_log.h>
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include <stdio.h>

#ifndef APP_CPU_NUM
#define APP_CPU_NUM PRO_CPU_NUM
#endif

#define SDA_PIN 15
#define SCL_PIN 16

static const char *TAG = "i2cscanner";

void task(void *ignore)
{

    i2c_config_t conf;
    conf.mode = I2C_MODE_MASTER;
    conf.sda_io_num = SDA_PIN;
    conf.scl_io_num = SCL_PIN;
    conf.sda_pullup_en = false;
    conf.scl_pullup_en = false;
    conf.master.clk_speed = 400000;
    i2c_param_config(I2C_NUM_0, &conf);

   i2c_driver_install(I2C_NUM_0, I2C_MODE_MASTER, 0, 0, 0);

    while (1)
    {
        esp_err_t res;
        printf("     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f\n");
        printf("00:         ");
        for (uint8_t i = 3; i < 0x78; i++)
        {
            i2c_cmd_handle_t cmd = i2c_cmd_link_create();
            i2c_master_start(cmd);
            i2c_master_write_byte(cmd, (i << 1) | I2C_MASTER_WRITE, 1 /* expect ack */);
            i2c_master_stop(cmd);

            res = i2c_master_cmd_begin(I2C_NUM_0, cmd, 10 / portTICK_PERIOD_MS);
            if (i % 16 == 0)
                printf("\n%.2x:", i);
            if (res == 0)
                printf(" %.2x", i);
            else
                printf(" --");
            i2c_cmd_link_delete(cmd);
        }
        printf("\n\n");
        vTaskDelay(pdMS_TO_TICKS(1000));
    }
}

void app_main()
{
    // Start task
    xTaskCreatePinnedToCore(task, TAG, configMINIMAL_STACK_SIZE * 8, NULL, 5, NULL, APP_CPU_NUM);
}
@espressif-bot espressif-bot added the Status: Opened Issue is new label Apr 7, 2022
@github-actions github-actions bot changed the title I2C communication failures on ESP32-S3 (works on ESP32) I2C communication failures on ESP32-S3 (works on ESP32) (IDFGH-7138) Apr 7, 2022
@ginkgm
Copy link
Collaborator

ginkgm commented Apr 7, 2022

Hi @CSHaze ,
Have you checked what's on the lines by a logic analyzer?
And are the lines pulled up by resistors correctly?

Michael

@CSHaze
Copy link
Author

CSHaze commented Apr 7, 2022

Hi @ginkgm, unfortunately I do not have access to a logic analyzer.

The Htu21d board I am using has built in pull up resistors. I have also tried unsoldering them and using the esp32-s3 internal pull ups and neither seems to work on the esp32-s3. The weird thing is, everything works correctly on the old esp32 I have. I am trying to swap to the newer s3 board.

I should be getting a bme280 board in the next couple days and I will test with that.

Are there differences in the i2c config or calls between the esp32 and esp32-s3? I did not see any differences in the docs.

@igrr
Copy link
Member

igrr commented Apr 7, 2022

It might not be the cause of the issue here, but could you try to zero-initialize the config structure (i2c_config_t) before filling it?
Currently there is a field clk_flags which isn't initialized and may contain random value from the stack.

@CSHaze
Copy link
Author

CSHaze commented Apr 8, 2022

Hi @ginkgm and @igrr. I just received a couple bme280 modules and i2c seems to be working fine.

Maybe I just have a couple of shoddy HTU21d modules. It is a little weird they seemed to work on the old esp32 though. Maybe due to differences in the internal clocks between the new and old esp32s?

@dhalbert
Copy link

dhalbert commented May 9, 2022

We are also seeing some I2C issues on ESP32-S3, though it's in comparison with ESP32-S2. Specifically, LC709203, an I2C battery meter, does not work reliably. It can work longer at slow I2C bus speeds (tested at 10kHz) but eventually produces I2C protocol errors. Other devices such as MSA301 or BNO055 (which can do clock stretching) seen OK at normal speeds. We're still trying to characterize the problem.

@dhalbert
Copy link

dhalbert commented May 12, 2022

(EDITED several times after I got a better comparison trace)

LC709203F comparison: maybe seeing a clock-stretching handling issue?

The first four transactions work, then the sensor does a long clock stretch. The clock stretch works on the S2 (bottom trace), but not the S3 (top trace)

image

Note that SDA goes high in the bad trace, which is odd.

I tried setting a 0.1sec I2C timeout, did not seem to help.

@dhalbert
Copy link

I cannot reproduce #8741 (comment) in Arduino on S3, using https://github.com/adafruit/Adafruit_LC709203F/tree/master/examples/LC709203F_demo and removing the delay in loop(). There are clock-stretches, but they don't cause issues above. The example above is from CircuitPython, which has an extra task and some other complications.

@lebossejames
Copy link

Hello,

I have same issue with ESP32-S3 Arduino IDE, i2C plug to lcd screen.

@Papirrruqui
Copy link

Hello, I just got a ESP32-S3HDevKitv1, and can't connect a I2C device to it. Can any one point me an example of how to configure the pins for I2C communication

@riker65
Copy link

riker65 commented Feb 25, 2023

same for me with heltec wifi kit 32 V3, no platformio module found for i2c but in arduino it is working with V3

@illuminati-vs
Copy link

Hey how did you configure pin 15&16 as i2c pins in ESP32-S3-Wroom-1, or are they by default i2c pins. Please help!!

@riker65
Copy link

riker65 commented Mar 20, 2023

Hi, on the heltec I used

`i2c:

sda: GPIO17
scl: GPIO18

scan: false
frequency: 50khz`

@Martius108
Copy link

Martius108 commented Apr 5, 2023

Hi riker65,

could you please post a full code example for Heltec boards? I tried to establish I2C connections to a BME280 sensor on CubeCell HTTC AB-02 and an ESP32 LoRa board (both V3) but nothing works. I always get "no I2C device found" I tried the second I2C channel which should be SDA = pin9 and SCL = pin8. I also tried different I2C scanners and was wondering why they couldn't find the build in OLED display ..

@riker65
Copy link

riker65 commented Apr 5, 2023

Hi

see here,

just my prototype to get it working

hope this helps

pasting it as code leads to strange formating

here without code tags

---again: strange format.
How do I supress those formating tags?

unfortunately have to redo it without the # inside

`#https://forum.hassiohelp.eu/d/536-display-oled-su-esp32-con-esphome
#https://github.com/Heltec-Aaron-Lee

esphome:
name: heltec2
platform: ESP32
board: esp32-s3-devkitc-1

wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password

#Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Oled2 Fallback Hotspot"
password: "xxxx"
captive_portal:
#Enable logging
logger:

ota:

#Example configuration entry
web_server:
port: 80

#https://esphome.io/components/switch/gpio.html
switch:

  • platform: gpio
    pin:
    number: 36
    id: mode
    restore_mode: RESTORE_DEFAULT_OFF

  • platform: gpio
    name: "LED_Int"
    pin:
    number: 35
    id: LED_Int
    icon: "mdi:gate"
    inverted: false
    restore_mode: RESTORE_DEFAULT_OFF

i2c:

sda: GPIO17
scl: GPIO18
scan: false
frequency: 50khz

font:

  • file: 'arialblk.ttf'
    id: font1
    size: 30
  • file: 'arial.ttf'
    id: font4
    size: 12
  • file: 'arial.ttf'
    id: font2
    size: 12
  • file: 'arial.ttf'
    id: font3
    size: 10

time:

  • platform: sntp
    id: sntp_time

display:

  • platform: ssd1306_i2c
    model: "SSD1306 128x64"
    reset_pin: GPIO21

    address: 0x3C
    setup_priority: 0
    id: my_display
    pages:

    • id: page1
      lambda: |-
      it.printf(0, 0, id(font3), "WP WT:%s",id(WPTemp).state.c_str());
      it.printf(70, 0, id(font3), "-%s",id(WPWT_TS).state.c_str());
      it.printf(0, 36, id(font3),"TS: %s",id(WPWT_TS).state.c_str());
      it.printf(0, 12, id(font3), "LWTLOL:%s",id(WPLOLLWT).state.c_str());
      it.printf(0, 24, id(font3), "LWTSICH:%s",id(WPSICHLWT).state.c_str());
      it.printf(100, 12, id(font4), TextAlign::TOP_CENTER, "TR");
      it.strftime(0, 52, id(font2), "%Y-%m-%d %H:%M:%S", id(sntp_time).now());

#https://esphome.io/components/mqtt.html
mqtt:
broker: 192.168.0.1
username: !secret mqtt_user
password: !secret mqtt_password

text_sensor:

  • platform: mqtt_subscribe
    name: "mqttWPTemp"
    id: WPTemp
    topic: WP/Was_temp
  • platform: mqtt_subscribe
    name: "WPWT_TS"
    id: WPWT_TS
    topic: WP/LOL/WT_PS
  • platform: mqtt_subscribe
    name: "mqttWPLOLLWT"
    id: WPLOLLWT
    topic: WP/LOL/LWT `

@slimcdk
Copy link

slimcdk commented Jun 28, 2023

@riker65 Not relevant here. ESPHome currently uses Arduino as core unless you explicitly define otherwise. Your question should be on their project instead.

@wBrhy2
Copy link

wBrhy2 commented Sep 21, 2023

I simply want to comment that I have observed similar issues as well where certain i2c chips behave differently between Wroom-32 and Wroom-S2/S3 as well. Specifically VL6180X chips and i2c touch panel. It renders those devices completely unusable on newer ESP32 so I look forward to seeing what you find.

@iyansrvc
Copy link

Same probelm I2C Not working on YD-ESP32-S3-N16-R8 (DeveKit-c1 clone)

@mythbuster5
Copy link
Collaborator

Which version are you use @iyansrvc ? With same stuff?

@Shravani-03
Copy link

Same probelm I2C Not working on YD-ESP32-S3-N16-R8 (DeveKit-c1 clone)

I have this exact board with the same problem, any help would be appreciated

@mythbuster5
Copy link
Collaborator

@Shravani-03 May I see your i2c related code and board?

@iyansrvc
Copy link

iyansrvc commented Jan 28, 2025 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Opened Issue is new
Projects
None yet
Development

No branches or pull requests