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);
}
Configuring Two I2C serial busses
-
- Posts: 9757
- Joined: Thu Nov 26, 2015 4:08 am
Re: Configuring Two I2C serial busses
The ESP32-C3 only has 1 I2C peripheral.
-
- Posts: 5
- Joined: Wed Apr 13, 2022 9:49 pm
Re: Configuring Two I2C serial busses
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.
-
- Posts: 9757
- Joined: Thu Nov 26, 2015 4:08 am
Re: Configuring Two I2C serial busses
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 161 guests