mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
ed1e32f583
Reported from different sources from github or bbs: https://github.com/espressif/esp-idf/issues/680 https://github.com/espressif/esp-idf/issues/922 We tested reading several sensor or other I2C slave devices, if the power and SDA/SCL wires are in proper condition, everything works find with reading the slave. If we remove the power supply for the slave during I2C is reading, or directly connect SDA or SCL to ground, this would cause the I2C FSM get stuck in wrong state, all we can do is the reset the I2C hardware in this case. After this commit, no matter whether the power supply of I2C slave is removed or SDA / SCL are shorted to ground, the driver can recover from wrong state. We are not sure whether this the save issue with the reported one yet, but to make the driver more robust. Further information: 1. For I2C master mode, we have tested different situations, e.g., to short the SDA/SCL directly to GND/VCC, to short the SDA to SCL, to un-plug the slave device, to power off the slave device. Under all of those situations, this version of driver can recover and keep working. 2. Some slave device will die by accident and keep the SDA in low level, in this case, master should send several clock to make the slave release the bus. 3. Slave mode of ESP32 might also get in wrong state that held the SDA low, in this case, master device could send a stop signal to make esp32 slave release the bus. Modifications: 1. Disable I2C_MASTER_TRAN_COMP interrupt to void extra interrupt. 2. Disable un-used timeout interrupt for slave. 3. Add bus reset if error detected for master mode. 4. Add bus clear if SDA level is low when error detected. 5. Modify the argument type of i2c_set_pin. 6. add API to set timeout value 7. add parameter check for timing APIs |
||
---|---|---|
.. | ||
main | ||
Makefile | ||
README.md |
I2C Example
-
This example will show you how to use I2C module by running two tasks on i2c bus:
- read external i2c sensor, here we use a BH1750 light sensor(GY-30 module) for instance.
- Use one I2C port(master mode) to read or write the other I2C port(slave mode) on one ESP32 chip.
-
Pin assignment:
- slave :
- GPIO25 is assigned as the data signal of i2c slave port
- GPIO26 is assigned as the clock signal of i2c slave port
- master:
- GPIO18 is assigned as the data signal of i2c master port
- GPIO19 is assigned as the clock signal of i2c master port
- slave :
-
Connection:
- connect GPIO18 with GPIO25
- connect GPIO19 with GPIO26
- connect sda/scl of sensor with GPIO18/GPIO19
- no need to add external pull-up resistors, driver will enable internal pull-up resistors.
-
Test items:
- read the sensor data, if connected.
- i2c master(ESP32) will write data to i2c slave(ESP32).
- i2c master(ESP32) will read data from i2c slave(ESP32).