Skip to content

Commit 0a5b435

Browse files
committed
[ESP32-s2] Fix crash when scanning I2C bus
See: espressif/arduino-esp32#5636
1 parent 9bf8961 commit 0a5b435

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/src/Helpers/Hardware.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@ void initI2C() {
173173
}
174174
addLog(LOG_LEVEL_INFO, F("INIT : I2C"));
175175
I2CSelectClockSpeed(false); // Set normal clock speed
176-
Wire.begin(Settings.Pin_i2c_sda, Settings.Pin_i2c_scl);
177176

178177
if (Settings.WireClockStretchLimit)
179178
{
@@ -226,8 +225,13 @@ void I2CSelectClockSpeed(bool setLowSpeed) {
226225
// No need to change the clock speed.
227226
return;
228227
}
229-
lastI2CClockSpeed = newI2CClockSpeed;
228+
lastI2CClockSpeed = newI2CClockSpeed;
229+
#ifdef ESP32
230+
Wire.begin(Settings.Pin_i2c_sda, Settings.Pin_i2c_scl, newI2CClockSpeed);
231+
#else
232+
Wire.begin(Settings.Pin_i2c_sda, Settings.Pin_i2c_scl);
230233
Wire.setClock(newI2CClockSpeed);
234+
#endif
231235
}
232236

233237
#ifdef FEATURE_I2CMULTIPLEXER

0 commit comments

Comments
 (0)