I have an ESP-WROOM-32 (I2C master) and an ATmega328p (I2C slave, address 0x03) assembled on a prototype PCB using external 6k8 pullups. I'm using the ESP's default I2C pins 21 (SDA) and 22 (SCL) as I always did, but when running the I2C scanner below, I do not observe any communication on the bus. SDA remains on high, SCL on low. The same sketch works as expected when I flashed it to another individual ESP32 (there I see communication on the bus and the slave is recognized at address 0x03). I'm very confused by that! I'm pretty sure there is no hardware issue on the PCB, because I verified it on a breadboard before giving it to the manufacturer and I have also tested the circuitry with a multimeter after the assembly. Also toggling pins 21 and 22 in software with high frequency works as intended. When I connect the other ESP32 to the same hardware, the signal has sufficient quality and is (at least) there.
As I don't think it has anything to do with my circuitry in general I wonder if there is a chance, that my ESP has been persistently misconfigured or if there are different firmware versions flashed by the manufacturer… Before debugging with my oscilloscope I flashed sketches that use the Wire.h, drivers/i2c.h and /peripherals/i2c.h, where I2C was set up on different pins (right now I don’t have access to those pins due to a shielding, so I can't check if there is a signal output). Does one of those libraries store any I2C configuration to SPIFFS or something like that?! Has anybody ever made the experience that gpios 21 and 22 show no activity with well known software, it seems like the interface was not even initialized? I can’t imagine I have a faulty chip... Any ideas?
The used I2C scanner (but I reproduced the problem with anything I did with Wire.h, drivers/i2c or peripherals/i2c.h):
#include <Wire.h>
#define SDA_PIN 21
#define SCL_PIN 22
void setup () {
Wire.begin(SDA_PIN, SCL_PIN);
Serial.begin(115200);
Serial.println("\nI2C Scanner");
}
void loop () {
byte error, address;
int nDevices;
Serial.println("Scanning...");
nDevices = 0;
for (address = 1; address < 127; address++ ) {
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0) {
Serial.print("I2C device found at address 0x");
if (address<16) {
Serial.print("0");
}
Serial.print(address,HEX);
Serial.println(" !");
nDevices++;
}
else if (error==4) {
Serial.print("Unknown error at address 0x");
if (address<16) {
Serial.print("0");
}
Serial.println(address,HEX);
}
}
if (nDevices == 0) {
Serial.println("No I2C devices found\n");
}
else {
Serial.println("done\n");
}
delay(1000);
}