Skip to content

Commit 798e73b

Browse files
authored
Fix i2c pin Glitch when Assigning Pins to I2C hardware
This pr fixes the signal glitches that occur when the SDA and SCL pins are attached to the I2C peripheral. The I2C bus is an open drain with external pullups. The initial device driver software set the pin drivers to OUTPUT_OPEN_DRAIN. This caused a low going transient that existed until the I2C peripheral gained ownership of the pin. When this pulse occurred on the SDA pin it caused an illegal bus transaction that intermittently hung the bus on init. (PAINFULL).
2 parents dfbc142 + 642d201 commit 798e73b

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

cores/esp32/esp32-hal-i2c.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,8 @@ i2c_err_t i2cAttachSCL(i2c_t * i2c, int8_t scl)
175175
if(i2c == NULL){
176176
return I2C_ERROR_DEV;
177177
}
178-
pinMode(scl, OUTPUT_OPEN_DRAIN | PULLUP);
178+
digitalWrite(scl, HIGH);
179+
pinMode(scl, OPEN_DRAIN | PULLUP);
179180
pinMatrixOutAttach(scl, I2C_SCL_IDX(i2c->num), false, false);
180181
pinMatrixInAttach(scl, I2C_SCL_IDX(i2c->num), false);
181182
return I2C_ERROR_OK;
@@ -197,7 +198,8 @@ i2c_err_t i2cAttachSDA(i2c_t * i2c, int8_t sda)
197198
if(i2c == NULL){
198199
return I2C_ERROR_DEV;
199200
}
200-
pinMode(sda, OUTPUT_OPEN_DRAIN | PULLUP);
201+
digitalWrite(sda, HIGH);
202+
pinMode(sda, OPEN_DRAIN | PULLUP);
201203
pinMatrixOutAttach(sda, I2C_SDA_IDX(i2c->num), false, false);
202204
pinMatrixInAttach(sda, I2C_SDA_IDX(i2c->num), false);
203205
return I2C_ERROR_OK;

0 commit comments

Comments
 (0)