-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Description
Board
ESP32, M5Stack, M5Stick etc.
Device Description
ESP32 Dev Module, M5STACK Core, M5Stick C and other
Hardware Configuration
I2C0 Slave Mode, SDA=GIO21, SCL=GPIO22
Version
v2.0.14
IDE Name
Arduino IDE or vMicro
Operating System
Windows10
Flash frequency
80Mhz
PSRAM enabled
yes
Upload speed
115200 - 921600
Description
Already back 2019 I have developed a working I2C slave implementation where master can read/write to address memory. BTW, this is still not working in Espressif IDE examples or Arduino Wire examples. It always sends garbage back to I2C Master because TX FIFO Empty & ACK/NACK not working. Anyhow, from time to time I'm updating to newest Arduino ESP32 when I need to make small changes in the code.
In my I2C slave implementation I have own, e.g.:
- I2C_param_config
- I2C_driver_install
- I2C_isr_register and own I2C_isr_handler
- I2C_callback_task
- and more
But since updating to 2.0.14 (cant remember which version I had before), my I2C Slave implementation did not work any more. It was working somehow but somehow not.
It took me over one week with different debugging tests until individual registers and interrupts until I figured out the problem and I think thats a general problem in Arduino ESP32 I2C implementation:
YOU MISS TO ENABLE THE I2C MODULE CLK !
I just added this two lines into my i2c_param_config code and all was working as before:
DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_I2C_EXT0_CLK_EN);
DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_I2C_EXT0_RST);
Interestingly, the I2C module is also working without the module CLK enables. I receive some data from I2C master and some parts of the code are working but other parts not. The problem is that without the module CLK, you cannot modify any registers defined in i2c_dev_t....and it obviously uses somehow the default values. It also gives no error messages from Espressif IDE.
I also checked the Arduino ESP32 Git code if I find some references to module CLK enable. I only found for SPI...here:
arduino-esp32/cores/esp32/esp32-hal-spi.c
Line 655 in 113de1f
#elif CONFIG_IDF_TARGET_ESP32 |
BR
Sketch
static DRAM_ATTR i2c_dev_t* const I2C_DEV[I2C_NUM_MAX] = { &I2C0, &I2C1 };
esp_err_t i2c_param_config(i2c_port_t i2c_num, const i2c_config_t* i2c_conf)
{
...
I2C_ENTER_CRITICAL(&i2c_spinlock[i2c_num]);
//needed to add this two lines to enable e.g. I2C0 module
DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_I2C_EXT0_CLK_EN);
DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_I2C_EXT0_RST);
...
if (i2c_conf->mode == I2C_MODE_SLAVE) {
...
I2C_DEV[i2c_num]->sda_hold.time = I2C_SLAVE_SDA_HOLD_DEFAULT;
I2C_DEV[i2c_num]->sda_sample.time = I2C_SLAVE_SDA_SAMPLE_DEFAULT;
}
I2C_EXIT_CRITICAL(&i2c_spinlock[i2c_num]);
return ESP_OK;
}
Debug Message
no debug message available
Other Steps to Reproduce
Try using Espressif IDE code and modify registers with i2c_dev_t struct, e.g. sda_hold.time or sda_sample.time
Reread the registers and you will see that nothing changed!
I have checked existing issues, online documentation and the Troubleshooting Guide
- I confirm I have checked existing issues, online documentation and Troubleshooting guide.