Skip to content

ESP32 S3 I2C issues when working as slave #10145

Closed
@JorgeMALopes

Description

@JorgeMALopes

Board

ESP32 S3 wroom 1

Device Description

Just an USB port, and a TI battery monitor.

Hardware Configuration

Currently only working with just the CPU, but has a TI battery monitor connected to the other I2C port.

Version

v3.0.3

IDE Name

Arduino IDE

Operating System

windows 10

Flash frequency

80MHz

PSRAM enabled

no

Upload speed

921600

Description

When i connect an ESP32S3 as an I2C slave to an ESP32 or a drone flight controller, as a master, the data comes out wrong.
When i reverse the code and the S3 is the master and the ESP32 is the slave then the data comes out correct.

I made a simple sketch where the slave returns 4 bytes when there is a request, 0x01FF0306 or 0x01FF03FF. The master requests a variable amount of bytes, sometimes more, sometimes less. When the S3 is the slave the first byte received from it is the slave address followed by part of the slave data. When the ESP32 is the slave then only data is returned.

I have asked a friend to lend me his oscilloscope so i can check the data lines for each case.

These are the lines for the S3 as a slave, notice the long time after the request and the repetition of the slave address.
scope_2
scope_1
scope_0

This is the lines for ESP32 as slave, the delay is minimal and there is no repetition of the slave address.
scope_3

The most stable case was then the returned bytes where of the same quantity as the requested ones, but sometimes the device address appears in the beginning and the only way to fix it is to reset the S3 which is not a viable solution.

I have tested with wire and wire1 and tested with other connections on the S3.

Sketch

-----------------------------------Slave code:-----------------------------

#include "Wire.h"             // i2c library

#define I2C_DEV_ADDR 0x30     // i2c adress, needs to be the same as in the lua script

typedef union {         // union for sending int via i2c
  int i;
  byte b[4];
} Dados_I;

Dados_I batata;

void setup() {
  Serial.begin(115200);        // start the serial port, used for debuging
  Serial.setDebugOutput(true);

  Wire.begin(I2C_DEV_ADDR,13,14,0);// start the i2c channel with the I2C_DEV_ADDR adress
  Wire.onRequest(onRequest);    // if there is a i2c request call then onRequest function is called
  Serial.println("setup");

  batata.i=0x01FF0306;
}

void loop() {
  // put your main code here, to run repeatedly:
}

void onRequest() {          // on request function, sends data via i2c depeding on the request
 Wire.write(batata.b, 4);
}

-----------------------------------master code:-----------------------------

#include "Wire.h"

#define I2C_DEV_ADDR 0x30

void setup() {
  Serial.begin(115200);
  Serial.setDebugOutput(true);
  Wire.begin();
}

void loop() {
  delay(100);

  uint8_t bytesReceived = Wire.requestFrom(I2C_DEV_ADDR, 2);
  Serial.printf("requestFrom: %u\n", bytesReceived);
  if ((bool)bytesReceived) {  //If received more than zero bytes
    uint8_t temp[bytesReceived];
    Wire.readBytes(temp, bytesReceived);
    log_print_buf(temp, bytesReceived);
  }
}

Debug Message

--------------ESP32 master:-------------

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1288
load:0x40078000,len:13872
load:0x40080400,len:4
ho 8 tail 4 room 4
load:0x40080404,len:3048
entry 0x40080590
[    16][D][esp32-hal-cpu.c:264] setCpuFrequencyMhz(): PLL: 480 / 2 = 240 Mhz, APB: 80000000 Hz
=========== Before Setup Start ===========
Chip Info:
------------------------------------------
  Model             : ESP32
  Package           : D0WD-Q5
  Revision          : 1.44
  Cores             : 2
  CPU Frequency     : 240 MHz
  XTAL Frequency    : 40 MHz
  Embedded Flash    : No
  Embedded PSRAM    : No
  2.4GHz WiFi       : Yes
  Classic BT        : Yes
  BT Low Energy     : Yes
  IEEE 802.15.4     : No
-----------------------------------------INTERNAL Memory Info:
------------------------------------------
  Total Size        :   382260 B ( 373.3 KB)
  Free Bytes        :   352228 B ( 344.0 KB)
  Allocated Bytes   :    22980 B (  22.4 KB)
  Minimum Free Bytes:   346716 B ( 338.6 KB)
  Largest Free Block:   118772 B ( 116.0 KB)
------------------------------------------
Flash Info:
------------------------------------------
  Chip Size         :  4194304 B (4 MB)
  Block Size        :    65536 B (  64.0 KB)
  Sector Size       :     4096 B (   4.0 KB)
  Page Size         :      256 B (   0.2 KB)
  Bus Speed         : 80 MHz
  Bus Mode          : DIO
------------------------------------------
Partitions Info:
------------------------------------------
                nvs : addr: 0x00009000, size:    20.0 KB, type: DATA, subtype: NVS
            otadata : addr: 0x0000E000, size:     8.0 KB, type: DATA, subtype: OTA
               app0 : addr: 0x00010000, size:  1280.0 KB, type:  APP, subtype: OTA_0
               app1 : addr: 0x00150000, size:  1280.0 KB, type:  APP, subtype: OTA_1
             spiffs : addr: 0x00290000, size:  1408.0 KB, type: DATA, subtype: SPIFFS
           coredump : addr: 0x003F0000, size:    64.0 KB, type: DATA, subtype: COREDUMP
------------------------------------------
Software Info:
------------------------------------------
  Compile Date/Time : Aug 12 2024 10:15:22
  Compile Host OS   : windows
  ESP-IDF Version   : v5.1.4-497-gdc859c1e67-dirty
  Arduino Version   : 3.0.3
------------------------------------------
Board Info:
------------------------------------------
  Arduino Board     : ESP32_DEV
  Arduino Variant   : doitESP32devkitV1
  Arduino FQBN      : esp32:esp32:esp32doit-devkit-v1:UploadSpeed=921600,FlashFreq=80,DebugLevel=debug,EraseFlash=none
============ Before Setup End ============
[   515][I][esp32-hal-i2c.c:109] i2cInit(): Initializing I2C Master: sda=21 scl=22 freq=100000
=========== After Setup Start ============
INTERNAL Memory Info:
------------------------------------------
  Total Size        :   382260 B ( 373.3 KB)
  Free Bytes        :   349208 B ( 341.0 KB)
  Allocated Bytes   :    25552 B (  25.0 KB)
  Minimum Free Bytes:   343696 B ( 335.6 KB)
  Largest Free Block:   118772 B ( 116.0 KB)
------------------------------------------
GPIO Info:
------------------------------------------
  GPIO : BUS_TYPE[bus/unit][chan]
  --------------------------------------  
     1 : UART_TX[0]
     3 : UART_RX[0]
    21 : I2C_MASTER_SDA[0]
    22 : I2C_MASTER_SCL[0]
============ After Setup End =============


-----------------esp32 S3 slave------------

CPU Frequency     : 240 MHz
setup
=========== Before Setup Start ===========
Chip Info:
------------------------------------------
  Model             : ESP32-S3
  Package           : 0
  Revision          : 2
  Cores             : 2
  CPU Frequency     : 240 MHz
  XTAL Frequency    : 40 MHz
  Embedded Flash    : No
  Embedded PSRAM    : No
  2.4GHz WiFi       : Yes
  Classic BT        : No
  BT Low Energy     : Yes
  IEEE 802.15.4     : No
------------------------------------------
INTERNAL Memory Info:
------------------------------------------
  Total Size        :   396660 B ( 387.4 KB)
  Free Bytes        :   364480 B ( 355.9 KB)
  Allocated Bytes   :    27292 B (  26.7 KB)
  Minimum Free Bytes:   359432 B ( 351.0 KB)
  Largest Free Block:   327668 B ( 320.0 KB)
------------------------------------------
Flash Info:
------------------------------------------
  Chip Size         : 16777216 B (16 MB)
  Block Size        :    65536 B (  64.0 KB)
  Sector Size       :     4096 B (   4.0 KB)
  Page Size         :      256 B (   0.2 KB)
  Bus Speed         : 80 MHz
  Bus Mode          : QIO
------------------------------------------
Partitions Info:
------------------------------------------
                nvs : addr: 0x00009000, size:    20.0 KB, type: DATA, subtype: NVS
            otadata : addr: 0x0000E000, size:     8.0 KB, type: DATA, subtype: OTA
               app0 : addr: 0x00010000, size:  3072.0 KB, type:  APP, subtype: OTA_0
               app1 : addr: 0x00310000, size:  3072.0 KB, type:  APP, subtype: OTA_1
               ffat : addr: 0x00610000, size: 10112.0 KB, type: DATA, subtype: FAT
           coredump : addr: 0x00FF0000, size:    64.0 KB, type: DATA, subtype: COREDUMP
------------------------------------------
Software Info:
------------------------------------------
  Compile Date/Time : Aug 12 2024 10:26:11
  Compile Host OS   : windows
  ESP-IDF Version   : v5.1.4-497-gdc859c1e67-dirty
  Arduino Version   : 3.0.3
------------------------------------------
Board Info:
------------------------------------------
  Arduino Board     : ESP32S3_DEV
  Arduino Variant   : esp32s3
  Arduino FQBN      : esp32:esp32:esp32s3:UploadSpeed=921600,USBMode=hwcdc,CDCOnBoot=cdc,MSCOnBoot=default,DFUOnBoot=default,UploadMode=default,CPUFreq=240,FlashMode=qio,FlashSize=16M,PartitionScheme=app3M_fat9M_16MB,DebugLevel=debug,PSRAM=disabled,LoopCore=1,EventsCore=1,EraseFlash=none,JTAGAdapter=default,ZigbeeMode=default
============ Before Setup End ============
[  1291][I][esp32-hal-periman.c:141] perimanSetPinBus(): Pin 19 already has type USB_DM (45) with bus 0x3fc965c4
[  1291][I][esp32-hal-periman.c:141] perimanSetPinBus(): Pin 20 already has type USB_DP (46) with bus 0x3fc965c4
[  1300][I][esp32-hal-i2c-slave.c:250] i2cSlaveInit(): Initializing I2C Slave: sda=14 scl=21 freq=100000, addr=0x30
[  1310][D][esp32-hal-i2c-slave.c:514] i2c_slave_set_frequency(): Fifo thresholds: rx_fifo_full = 28, tx_fifo_empty = 4
setup
=========== After Setup Start ============
INTERNAL Memory Info:
------------------------------------------
  Total Size        :   396660 B ( 387.4 KB)
  Free Bytes        :   358416 B ( 350.0 KB)
  Allocated Bytes   :    33052 B (  32.3 KB)
  Minimum Free Bytes:   353320 B ( 345.0 KB)
  Largest Free Block:   327668 B ( 320.0 KB)
------------------------------------------
GPIO Info:
------------------------------------------
  GPIO : BUS_TYPE[bus/unit][chan]
  --------------------------------------  
    14 : I2C_SLAVE_SDA[0]
    19 : USB_DM
    20 : USB_DP
    21 : I2C_SLAVE_SCL[0]
    43 : UART_TX[0]
    44 : UART_RX[0]
============ After Setup End =============

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions