Issues with using multiprocessing and TwoWire I2C

dmr-rocha
Posts: 4
Joined: Thu Jun 02, 2022 1:59 pm

Issues with using multiprocessing and TwoWire I2C

Postby dmr-rocha » Thu Jun 02, 2022 2:04 pm

Good Morning!

I'm doing a project in which I use the two processors separately and two I2C channels ( TwoWire ), where in each processor I use an I2C channel.

The Zero Processor is used for sensor reading routines through the I2C channel (INA219, BME680, ADS1115, DS1302), storing the values in global variables .

The Processor A use for the other routines and control of the LCD and keyboard, both I2C and demonstration of the values of the global variables .

In the compilation everything works , but after turning on Esp32 it works for a few seconds and then crashes.

I'm using I2C as follows :

TwoWire I2C_1 = TwoWire ( 0);
TwoWire I2C_2 = TwoWire ( 1);

I2C_ 1.begin (21, 22, 100000);
I2C_ 2.begin (15, 4, 100000);

The Processors I am creating as follows :

xTaskCreatePinnedToCore ( CoreZero , " CoreZero ", 16392, NULL, 5, NULL, 0);
delay ( 500);

xTaskCreatePinnedToCore ( CoreOne , " CoreOne ", 16392, NULL, 5, NULL, 1);
delay ( 500);

void loop( ) {

vTaskDelete ( NULL);

}

Observation:

The processors being used one without routine in the other works perfectly, however the two connected together does not work.

I need help trying to clarify the problem and whoever helps me to clarify I will give a payment.

Thanks.

User avatar
gtjoseph
Posts: 92
Joined: Fri Oct 15, 2021 10:55 pm

Re: Issues with using multiprocessing and TwoWire I2C

Postby gtjoseph » Sat Jun 04, 2022 4:17 pm

What exactly are the crash details?

The original Arduino TwoWire code was never thread-safe. The version in the arduino-esp32 component attempts to be but you need to make sure that CONFIG_DISABLE_HAL_LOCKS is NOT set in your sdkconfig. Even still, it's not perfect. Seeing the crash dump will help understand what's going on.

dmr-rocha
Posts: 4
Joined: Thu Jun 02, 2022 1:59 pm

Re: Issues with using multiprocessing and TwoWire I2C

Postby dmr-rocha » Wed Jun 15, 2022 12:58 am

When I start Esp32 it works for a few seconds and crashes. The routines that run on Processor Zero are reading the sensors and devices that I have listed, placed all on a processor works perfectly, when divided into two Wires the problems begin.

I wanted to check if it was possible to work the way I'm trying.

The bug message follows.

thanks
Attachments
bug.txt
(2.01 KiB) Downloaded 242 times
1655252881396.jpg
1655252881396.jpg (3.99 MiB) Viewed 3143 times
1655252881383.jpg
1655252881383.jpg (3.87 MiB) Viewed 3143 times

User avatar
gtjoseph
Posts: 92
Joined: Fri Oct 15, 2021 10:55 pm

Re: Issues with using multiprocessing and TwoWire I2C

Postby gtjoseph » Wed Jun 15, 2022 10:58 am

As I said, the original TwoWire Arduino code was never thread-safe. Espressif had to add a lot of locking to get that model to work in multiple threads and even with that, it's not perfect.

The only suggestions I have are...
  1. Check the setting of DISABLE_HAL_LOCKS under Arduino in menuconfig.
  2. Can you split usage of the busses so that bus 1 is only accessed from Core 1 and bus 2 is only accessed from Core 2? Maybe create queues so that if one core needs data from the other bus, it can queue a request to the other core?
  3. Under ESP System Settings, set Panic handler behaviour to GDBStub on panic so you can see which threads are blocked on what.
  4. Search for ESP32 native drivers for your I2C devices so you don't have to use the Arduino TwoWire component.
I'm using I2C in a similar situation (sensors and I/O) and wound up using options 2 and 4.

dmr-rocha
Posts: 4
Joined: Thu Jun 02, 2022 1:59 pm

Re: Issues with using multiprocessing and TwoWire I2C

Postby dmr-rocha » Thu Jun 16, 2022 1:02 am

Thank you friend,

I will explore your suggestions and get back to you.

Who is online

Users browsing this forum: No registered users and 108 guests