Hey,
for some days I am trying to get an i2c connection between two ESP32 running. After having serious issues with reliability in my main project, I wanted to try around with a simple project.
I adapted the example from espressif (https://github.com/espressif/esp-idf/tr ... _self_test), so it is running on two devices, one master, one slave.
However, sometimes the master seems to just abort writing. This happens irregular and after different numbers of successfully sent bytes. The return of i2c_master_cmd_begin is either ESP_FAIL or ESP_ERR_TIMEOUT. The logic analyzer shows, that the byte-stream just stops with NAK. See attached screenshot, it's supposed to count up from 0x0a to 0x89.
My sample program is here.
https://github.com/juri117/esp32_i2c_master
https://github.com/juri117/esp32_i2c_slave
The hardware setup is:
Master ESP GPIO 18 -> Master ESP GPIO 21
Master ESP GPIO 19 -> Master ESP GPIO 22
After running this example for one minute I get at least one master write failure.
Please, any new ideas are appreciated, I don't know what else to try.
i2c master aborts write
i2c master aborts write
- Attachments
-
- Screenshot 2019-05-31 21.53.22.png (172.76 KiB) Viewed 5114 times
Re: i2c master aborts write
Hi,
Which ESP32 IDF you are using into your development process?
Did you try connecting any I2C Device other then ESP32 with single ESP32 Device? If not then I suggest to try one time to verify that it is really software issue or hardware issue.
Which ESP32 IDF you are using into your development process?
Did you try connecting any I2C Device other then ESP32 with single ESP32 Device? If not then I suggest to try one time to verify that it is really software issue or hardware issue.
Regards,
Ritesh Prajapati
Ritesh Prajapati
Re: i2c master aborts write
hey, thanks for the reply, sry I should have mentioned that:
I am using esp-idf (https://github.com/espressif/esp-idf) tag: v3.2
I am using a BMP180 pressure sensor that works great. But there the ESP32 as master writes and reads maximum 2 Bytes at a time and I read from registers. With the 2nd ESP32 as slave I couldn't find a way to make the master read from a register, which I would prefer. With the fifo I am never sure how many bytes got dropped and how many bytes are available to read in the first place.
I am using esp-idf (https://github.com/espressif/esp-idf) tag: v3.2
I am using a BMP180 pressure sensor that works great. But there the ESP32 as master writes and reads maximum 2 Bytes at a time and I read from registers. With the 2nd ESP32 as slave I couldn't find a way to make the master read from a register, which I would prefer. With the fifo I am never sure how many bytes got dropped and how many bytes are available to read in the first place.
Re: i2c master aborts write
After trying to distract me with other work I had to come back to the problem and got it running by now.
I think the main problem was timing. Also, the master seems to stop working once it tried to read without the slave having sent anything.
One big issue I found was, that I had the ground connection only via the two USB cables and the PC. Usually that was enough for e.g. UART but I2C needs a direct GND connection between the two ESP32!
So my new approach works like common I2C register communication. The master sends a request for specific data, then waits for a fixed period of time, while the slave puts some data (with fixed length) into the out buffer. Then the master reads without risking reading nothing. Seems stable. However, I miss a way to check the length of the out buffer on the slave side, to know whether the master read the bytes. If anyone needs a working two devices I2C ESP32 to ESP32 example, please benefit from my experiments
Master:
https://github.com/juri117/esp32-i2c-slave
Slave:
https://github.com/juri117/esp32-i2c-slave
I think the main problem was timing. Also, the master seems to stop working once it tried to read without the slave having sent anything.
One big issue I found was, that I had the ground connection only via the two USB cables and the PC. Usually that was enough for e.g. UART but I2C needs a direct GND connection between the two ESP32!
So my new approach works like common I2C register communication. The master sends a request for specific data, then waits for a fixed period of time, while the slave puts some data (with fixed length) into the out buffer. Then the master reads without risking reading nothing. Seems stable. However, I miss a way to check the length of the out buffer on the slave side, to know whether the master read the bytes. If anyone needs a working two devices I2C ESP32 to ESP32 example, please benefit from my experiments
Master:
https://github.com/juri117/esp32-i2c-slave
Slave:
https://github.com/juri117/esp32-i2c-slave
Re: i2c master aborts write
Thanks for your findings for same.dieg0_ wrote: ↑Sat Aug 17, 2019 4:16 pmAfter trying to distract me with other work I had to come back to the problem and got it running by now.
I think the main problem was timing. Also, the master seems to stop working once it tried to read without the slave having sent anything.
One big issue I found was, that I had the ground connection only via the two USB cables and the PC. Usually that was enough for e.g. UART but I2C needs a direct GND connection between the two ESP32!
So my new approach works like common I2C register communication. The master sends a request for specific data, then waits for a fixed period of time, while the slave puts some data (with fixed length) into the out buffer. Then the master reads without risking reading nothing. Seems stable. However, I miss a way to check the length of the out buffer on the slave side, to know whether the master read the bytes. If anyone needs a working two devices I2C ESP32 to ESP32 example, please benefit from my experiments
Master:
https://github.com/juri117/esp32-i2c-slave
Slave:
https://github.com/juri117/esp32-i2c-slave
We will check it and utilize it as per our requirements.
Regards,
Ritesh Prajapati
Ritesh Prajapati
Who is online
Users browsing this forum: No registered users and 61 guests