arduino-esp32 icon indicating copy to clipboard operation
arduino-esp32 copied to clipboard

FW got into blocking state if Wire (I2C) is used in a constructor of a custom class

Open rob-bits opened this issue 3 years ago • 1 comments

Board

ESP32-S3 breadboard

Device Description

Unique developed hardware with ESP32-S3. I2C bus is tested, pca9534 is connected to the I2C bus with external 10k pull ups to 3.3V.

Hardware Configuration

GPIO9 (SDA), GPIO48 (SCL)

Version

v2.0.4

IDE Name

PlatformIO

Operating System

Windows 10

Flash frequency

40

PSRAM enabled

no

Upload speed

115200

Description

The ESP32 FW is blocked if I2C Wire functions are called in a class constructor when the instance of the class created globally.

Implementing the following class:

#include <Wire.h>

MyClass::MyClass(int sda, int scl, int addr):sda_pin(sda), scl_pin(scl), address(addr)
{
    Wire.begin(sda_pin, scl_pin, 100000U);
    Wire.beginTransmission(address);
    Wire.write(0x03);
    Wire.write(0xFF);
    error = Wire.endTransmission();
}

And creating a instance in the main.cpp:

MyClass mMyClass(9, 48, 61);

Working code:

#include <Wire.h>

MyClass::MyClass(int sda, int scl, int addr):sda_pin(sda), scl_pin(scl), address(addr)
{
    Wire.begin(sda_pin, scl_pin, 100000U);
}

MyClass::init()
{
    Wire.beginTransmission(address);
    Wire.write(0x03);
    Wire.write(0xFF);
    error = Wire.endTransmission();
}

In the working code the init() is called in the setup() part of the code.

In the malfunctioned code the class blocks the execution. No error message is printed in terminal. After 5-10 sec the board restarts because of the watchdog.

Here is the anomaly on the bus: image

Working state if with the working code: image

Expected behavior: If Wire is not available yet, because the instance of my class runs sooner than the Wire got inited, I would expect a log_e error message.

Sketch

It has described above.

Debug Message

No error message is printed (no log_e)

Other Steps to Reproduce

No response

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

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

rob-bits avatar Aug 09 '22 07:08 rob-bits

@rob-bits - Could you please set "Core debug Level:" to "Verbose" and post here the output of both use cases presented in this issue?

I may help in tracking what is being executed in Wire API. Thanks.

SuGlider avatar Aug 10 '22 23:08 SuGlider