Skip to content

Commit e14b148

Browse files
authored
Merge pull request #3803 from skieast/fix_i2c_hang_with_wifi
Working, tested with two i2c busses
2 parents 1330130 + 571c063 commit e14b148

File tree

1 file changed

+14
-9
lines changed
  • ports/esp32s2/common-hal/busio

1 file changed

+14
-9
lines changed

ports/esp32s2/common-hal/busio/I2C.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ void never_reset_i2c(i2c_port_t num) {
4949
void i2c_reset(void) {
5050
for (i2c_port_t num = 0; num < I2C_NUM_MAX; num++) {
5151
if (i2c_status[num] == STATUS_IN_USE) {
52-
i2c_driver_delete(num);
5352
i2c_status[num] = STATUS_FREE;
5453
}
5554
}
5655
}
56+
static bool i2c_inited[I2C_NUM_MAX];
5757

5858
void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
5959
const mcu_pin_obj_t* scl, const mcu_pin_obj_t* sda, uint32_t frequency, uint32_t timeout) {
@@ -121,13 +121,19 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
121121
if (result != ESP_OK) {
122122
mp_raise_ValueError(translate("Invalid pins"));
123123
}
124-
result = i2c_driver_install(self->i2c_num,
125-
I2C_MODE_MASTER,
126-
0,
127-
0,
128-
0);
129-
if (result != ESP_OK) {
130-
mp_raise_OSError(MP_EIO);
124+
125+
126+
if (!i2c_inited[self->i2c_num]) {
127+
result = i2c_driver_install(self->i2c_num,
128+
I2C_MODE_MASTER,
129+
0,
130+
0,
131+
0);
132+
if (result != ESP_OK) {
133+
mp_raise_OSError(MP_EIO);
134+
}
135+
i2c_inited[self->i2c_num] = true;
136+
131137
}
132138

133139
claim_pin(sda);
@@ -143,7 +149,6 @@ void common_hal_busio_i2c_deinit(busio_i2c_obj_t *self) {
143149
return;
144150
}
145151

146-
i2c_driver_delete(self->i2c_num);
147152
i2c_status[self->i2c_num] = STATUS_FREE;
148153

149154
common_hal_reset_pin(self->sda_pin);

0 commit comments

Comments
 (0)