Skip to content

Commit 3a7a9bb

Browse files
committed
Make I2C work reliably with interrupts
Thanks @marcmerlin and @MartyMacGyver
1 parent b1bb9a9 commit 3a7a9bb

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

Diff for: cores/esp32/esp32-hal-i2c.c

+6-4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
#define I2C_SCL_IDX(p) ((p==0)?I2CEXT0_SCL_OUT_IDX:((p==1)?I2CEXT1_SCL_OUT_IDX:0))
2828
#define I2C_SDA_IDX(p) ((p==0)?I2CEXT0_SDA_OUT_IDX:((p==1)?I2CEXT1_SDA_OUT_IDX:0))
2929

30+
#define DR_REG_I2C_EXT_BASE_FIXED 0x60013000
31+
#define DR_REG_I2C1_EXT_BASE_FIXED 0x60027000
3032

3133
struct i2c_struct_t {
3234
i2c_dev_t * dev;
@@ -49,16 +51,16 @@ enum {
4951
#define I2C_MUTEX_UNLOCK()
5052

5153
static i2c_t _i2c_bus_array[2] = {
52-
{(volatile i2c_dev_t *)(DR_REG_I2C_EXT_BASE), 0},
53-
{(volatile i2c_dev_t *)(DR_REG_I2C1_EXT_BASE), 1}
54+
{(volatile i2c_dev_t *)(DR_REG_I2C_EXT_BASE_FIXED), 0},
55+
{(volatile i2c_dev_t *)(DR_REG_I2C1_EXT_BASE_FIXED), 1}
5456
};
5557
#else
5658
#define I2C_MUTEX_LOCK() do {} while (xSemaphoreTake(i2c->lock, portMAX_DELAY) != pdPASS)
5759
#define I2C_MUTEX_UNLOCK() xSemaphoreGive(i2c->lock)
5860

5961
static i2c_t _i2c_bus_array[2] = {
60-
{(volatile i2c_dev_t *)(DR_REG_I2C_EXT_BASE), NULL, 0},
61-
{(volatile i2c_dev_t *)(DR_REG_I2C1_EXT_BASE), NULL, 1}
62+
{(volatile i2c_dev_t *)(DR_REG_I2C_EXT_BASE_FIXED), NULL, 0},
63+
{(volatile i2c_dev_t *)(DR_REG_I2C1_EXT_BASE_FIXED), NULL, 1}
6264
};
6365
#endif
6466

0 commit comments

Comments
 (0)