Skip to content

Commit 1cf4270

Browse files
stickbreakerme-no-dev
authored andcommitted
Add Hardware Reset when Initing I2C peripheral (espressif#1201)
This change uses the `_RST` bit of the i2c peripheral to force the hardware into power on reset state. The prior code assumed the peripheral was already in a reset, it just cleared the reset bit. Chuck.
1 parent 14ed6c4 commit 1cf4270

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

cores/esp32/esp32-hal-i2c.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -444,11 +444,13 @@ i2c_t * i2cInit(uint8_t i2c_num, uint16_t slave_addr, bool addr_10bit_en)
444444
#endif
445445

446446
if(i2c_num == 0) {
447+
DPORT_SET_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG,DPORT_I2C_EXT0_RST); // I2C0 peripheral into Reset mode
447448
DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG,DPORT_I2C_EXT0_CLK_EN);
448-
DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG,DPORT_I2C_EXT0_RST);
449+
DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG,DPORT_I2C_EXT0_RST); // Release Reset Mode
449450
} else {
451+
DPORT_SET_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG,DPORT_I2C_EXT1_RST); // I2C1 peripheral into Reset Mode
450452
DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG,DPORT_I2C_EXT1_CLK_EN);
451-
DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG,DPORT_I2C_EXT1_RST);
453+
DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG,DPORT_I2C_EXT1_RST); // Release Reset Mode
452454
}
453455

454456
I2C_MUTEX_LOCK();

0 commit comments

Comments
 (0)