Configuring Two I2C serial busses

baudenbacher
Posts: 5
Joined: Wed Apr 13, 2022 9:49 pm

Configuring Two I2C serial busses

Postby baudenbacher » Wed Apr 27, 2022 2:09 pm

I have a ESP32-C3-WROM-02 and have been trying to get two I2C buses one on Pins 0, 1 and the other on Pins 2, 3 (or 18,19) to work simultaneously.
I use the Arduino IDE and the Wire.h code. I get each bus to work but when I try to run them together I only get results from the first one. I used the following code and it returns the address of the slaves on IC2Cone (or Wire) only. It seems that I can not run two controllers at the same time. Is this correct?


#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_ADXL343.h>

// extern TwoWire Wire1;
// extern TwoWire Wire;

//logMessage is my logger.. replace this by Serial.println or something..
//

TwoWire I2Cone = TwoWire(0);
TwoWire I2Ctwo = TwoWire(1);


void setup (){

uint32_t freq = 100000;

Serial.begin(115200);
Serial.println("test");

I2Cone.begin(0, 1, freq); // Wire.begin(0,1);
I2Ctwo.begin(18, 19, freq); // Wire1.begin(18,19)

Serial.println("I2C scanner. Scanning bus 0...");
for (byte i = 8; i < 127; i++)
{
I2Cone.beginTransmission(i);
if (I2Cone.endTransmission() == 0)
{
Serial.println("Found address: " + String(i));
// check address
if ((i == 32) or (i == 39))
{
// found device, do something..
}

delay(1);
}
}
I2Cone.endTransmission();

Serial.println("I2C scanner. Scanning bus 1...");

for (byte i = 8; i < 127; i++)
{
I2Ctwo.beginTransmission(i);
if (I2Ctwo.endTransmission() == 0)
{
Serial.println("Found address: " + String(i));
// check address
if (i == 64)
{
// found device, do something..
}

delay(1);
}
}
I2Ctwo.endTransmission();

Serial.println("I2C device check DONE!\n");

}
void loop() {

setup();
delay(10000);

}

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

Re: Configuring Two I2C serial busses

Postby ESP_Sprite » Thu Apr 28, 2022 2:09 am

The ESP32-C3 only has 1 I2C peripheral.

baudenbacher
Posts: 5
Joined: Wed Apr 13, 2022 9:49 pm

Re: Configuring Two I2C serial busses

Postby baudenbacher » Fri Apr 29, 2022 2:03 am

I switched to the ESP32-WROM-32E and the code works perfectly. I thought you could configure any pair of pins to implement a I2C serial bus.

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

Re: Configuring Two I2C serial busses

Postby ESP_Sprite » Fri Apr 29, 2022 6:03 am

You can configure any pair of pins to connect to the I2C peripheral, however you only have one I2C peripheral available.

Who is online

Users browsing this forum: No registered users and 52 guests