XIAO ESP32C6 I2C Slave Pins?

I am trying to replace a XIAO ESP32S3 that I use as an I2C slave sender with an ESP32C6, but just cannot figure what I am doing wrong.

For the ESP32S3 I use the following code and it works great…

#include <Wire.h>

void I2C_TxHandler(void) {
  Wire.slaveWrite(TxByte, 4);
}

void setup() {
  Wire.onRequest(I2C_TxHandler);
  Wire.begin(0x42, 5, 6, 100000UL);
}

void loop() {
  delay(10);
}

But when I swap in the ESP32C6 and modify the pins it doesn’t work at all…

#include <Wire.h>

void I2C_TxHandler(void) {
  Wire.slaveWrite(TxByte, 4);
}

void setup() {
  Wire.onRequest(I2C_TxHandler);
  Wire.begin(0x42, 22, 23, 100000UL);
}

void loop() {
  delay(10);
}

D4 & D5 are the corresponding pins GPIO22 & GPIO23 according to the pin diagram.
Does anyone know what I am doing wrong?
Thank you!

As you say the pin swap should be correct… must be something in the Library support for C6

Hi there,

Which BSP are you using for the C6 compile ? The Pin macros may be used in this case if newer, ie. D4 & D5 in both cases.

Can you provide the compiler output for the S3 that works? the first 3 lines and the last 10 -12 before it uploads.
We can take a look. :+1:

HTH
GL :slight_smile: PJ :v:

meanwhile… Here is why it’s not working.

  • On ESP32-S3, Wire.onRequest() works because S3 supports I2C slave mode in hardware and in the Arduino core.

  • On ESP32-C6, only I2C Master mode is implemented in the Arduino Wire library as of BSP 3.2.0. "

  • Wire.onRequest() is not implemented for ESP32-C6 as of BSP v3.x (and even earlier).

  • Wire.slaveWrite() and I2C Slave Mode is not supported on the ESP32-C6 using the Arduino Wire library.

  • Even the call:

Wire.begin(0x42, 5, 6, 100000UL);

while syntactically valid, doesn’t actually configure the ESP32-C6 as an I2C slave, because slave mode isn’t available in the current ESP32-C6 Arduino core.
Wait for future support — but no timeline is guaranteed for I2C slave in ESP32-C6 via Arduino.

3 Likes

I knew it was a software support thing…

Thank you both for the explanation and feedback.
I will find a work around for the lack of the I2C slave mode on the C6.

1 Like

Hi there,

Good don’t give up. :+1:
I’m working on a BLE kind of a solution. Not sure it it would help , but I’ll post it up in the Round Display thread tomorrow. you may be able to use something from that.

HTH
GL :slight_smile: PJ

Espressif , should get there act together , let’s hope. :crossed_fingers:

1 Like

Thanks - I will check out your Round Display thread.
But my main controller does not have BLE or WiFi…I am actually using the XIAO to create an I2C “sensor” that forwards data from a BLE sensor.
That’s why I was using Slave mode.
I can convert the XIAO C6 to push the data to the controller set up with a 2nd I2C slave interface, but I preferred the controller just requesting the the data payload on-demand.
I am also looking at the MG24, but the Silicon Labs BLE stack is very very complicated for a novice like me who doesn’t know what they are doing.
I have been very lucky so far to get what I have working.

I have a BLE sensor that has a GATT update characteristic (not sure if that is the right name) you can subscribe to notifications, and it delivers a 50 byte payload.
I need to get that payload to a controller that has other I2C sensors and outputs.
I was able to get the ArduinoBLE library working with the ESP32-S3, but a recent firmware update for the BLE sensor somehow broke it and now the sensor crashes seconds after the subscription is made and the first few notifications are received.
I cannot expect changes to the BLE sensor to fix it.
When I tried the ESP32-C6, subscriptions work great, but the XIAO wasn’t sending the data, which you taught me is because it doesn’t support slave mode.
The nRF52840 kinda works, but it isn’t as stable or reliable as the ESP32’s, and the Discovery and Subscribe phases fail a lot of the time.

I just need to scan for a MAC, and when it finds it, subscribe to the notifications…not as simple as it sounds

Thanks again for your help!