Page 1 of 1

ESP32 I2C PCF8574 read issue

Posted: Mon Jul 01, 2019 3:30 am
by jgustavoam
In February 2018, I ran my sketch (arduino IDE) in my project - ESP32 digital voltmeter and it worked fine -
Arduino IDE 1.8.5 and ESP32 Board version 1.0.0.
The communication of the digital voltmeter is made with PCF8574 I2C interface. Pullups resistors are 3K3 ohms (VCC = 3.3V)
https://www.elektormagazine.com/labs/es ... /labs/1459
https://github.com/Gustavomurta/ESP32-DVM

The complete voltmeter reading data code is:
https://github.com/Gustavomurta/ESP32-D ... _PT_V1.ino

Code: Select all

 Wire.begin();                   // Start I2C
  Wire.requestFrom(PCF8574, 1);   // Read One Byte from PCF8574
  pcfData = Wire.read();          // Byte Read
Now with Arduino 1.8.9 and ESP32 Board version 1.0.2, the I2C runs in crazy mode. The SCL pin sends continuous pulses and the SDA sends erroneous data (checked with logic analyzer).
My ESP32 is DOIT ESP32 DevKit V1 and the hardware is OK and checked with my I2C scanner. (based on Nick Gammon).

https://github.com/Gustavomurta/ESP32-D ... anner2.ino
https://github.com/Gustavomurta/ESP32-D ... 5%20V3.jpg


Researching this problem with the Debug option, I found these messages, but I do not know what it is meaning.

Code: Select all

debugFlags=0x00000000
[I][esp32-hal-i2c.c:311] i2cDumpDqData(): Debug Buffer not Enabled
[I][esp32-hal-i2c.c:354] i2cDumpInts(): Debug Buffer not Enabled
[D][esp32-hal-i2c.c:1336] i2cProcQueue():  Busy Timeout start=0x303a4, end=0x303a4, =0, max=50 error=0
[E][esp32-hal-i2c.c:318] i2cDumpI2c(): i2c=0x3ffbebe0
[I][esp32-hal-i2c.c:319] i2cDumpI2c(): dev=0x60013000 date=0x16042000
[I][esp32-hal-i2c.c:321] i2cDumpI2c(): lock=0x3ffb84ec
[I][esp32-hal-i2c.c:323] i2cDumpI2c(): num=0
[I][esp32-hal-i2c.c:324] i2cDumpI2c(): mode=1
[I][esp32-hal-i2c.c:325] i2cDumpI2c(): stage=3
[I][esp32-hal-i2c.c:326] i2cDumpI2c(): error=0
[I][esp32-hal-i2c.c:327] i2cDumpI2c(): event=0x3ffb8570 bits=0
[I][esp32-hal-i2c.c:328] i2cDumpI2c(): intr_handle=0x3ffb85a0
[I][esp32-hal-i2c.c:329] i2cDumpI2c(): dq=0x3ffb854c
[I][esp32-hal-i2c.c:330] i2cDumpI2c(): queueCount=1
[I][esp32-hal-i2c.c:331] i2cDumpI2c(): queuePos=0
[I][esp32-hal-i2c.c:332] i2cDumpI2c(): errorByteCnt=0
[I][esp32-hal-i2c.c:333] i2cDumpI2c(): errorQueue=0
[I][esp32-hal-i2c.c:334] i2cDumpI2c(): debugFlags=0x00000000

Can someone help me? Thanks in advance.

Re: ESP32 I2C PCF8574 read issue

Posted: Mon Jul 01, 2019 1:42 pm
by jgustavoam
I was not setting DEBUG Mode correctly !
Now setting OK .

https://github.com/espressif/arduino-es ... bugging.md

Code: Select all

rst:0x10 (RTCWDT_RTC_RESET),boot:0x17 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:928
ho 0 tail 12 room 4
load:0x40078000,len:8424
ho 0 tail 12 room 4
load:0x40080400,len:5868
entry 0x4008069c
[D][esp32-hal-i2c.c:1337] i2cProcQueue():  Busy Timeout start=0xd5, end=0xd5, =0, max=50 error=0
[E][esp32-hal-i2c.c:319] i2cDumpI2c(): i2c=0x3ffbebe0
[I][esp32-hal-i2c.c:320] i2cDumpI2c(): dev=0x60013000 date=0x16042000
[I][esp32-hal-i2c.c:322] i2cDumpI2c(): lock=0x3ffb84ec
[I][esp32-hal-i2c.c:324] i2cDumpI2c(): num=0
[I][esp32-hal-i2c.c:325] i2cDumpI2c(): mode=1
[I][esp32-hal-i2c.c:326] i2cDumpI2c(): stage=3
[I][esp32-hal-i2c.c:327] i2cDumpI2c(): error=0
[I][esp32-hal-i2c.c:328] i2cDumpI2c(): event=0x3ffb8570 bits=0
[I][esp32-hal-i2c.c:329] i2cDumpI2c(): intr_handle=0x3ffb85a0
[I][esp32-hal-i2c.c:330] i2cDumpI2c(): dq=0x3ffb854c
[I][esp32-hal-i2c.c:331] i2cDumpI2c(): queueCount=1
[I][esp32-hal-i2c.c:332] i2cDumpI2c(): queuePos=0
[I][esp32-hal-i2c.c:333] i2cDumpI2c(): errorByteCnt=0
[I][esp32-hal-i2c.c:334] i2cDumpI2c(): errorQueue=0
[I][esp32-hal-i2c.c:335] i2cDumpI2c(): debugFlags=0x00000000
[I][esp32-hal-i2c.c:289] i2cDumpDqData(): [0] 7bit 20 R STOP buf@=0x3ffbfeb8, len=1, pos=0, ctrl=11110
[I][esp32-hal-i2c.c:307] i2cDumpDqData(): 0x0000: .                                00 
[I][esp32-hal-i2c.c:347] i2cDumpInts(): 0 row	count	INTR	TX	RX	Tick 

[D][esp32-hal-i2c.c:1337] i2cProcQueue():  Busy Timeout start=0x131, end=0x131, =0, max=50 error=0
[E][esp32-hal-i2c.c:319] i2cDumpI2c(): i2c=0x3ffbebe0
[I][esp32-hal-i2c.c:320] i2cDumpI2c(): dev=0x60013000 date=0x16042000
[I][esp32-hal-i2c.c:322] i2cDumpI2c(): lock=0x3ffb84ec
[I][esp32-hal-i2c.c:324] i2cDumpI2c(): num=0
[I][esp32-hal-i2c.c:325] i2cDumpI2c(): mode=1
[I][esp32-hal-i2c.c:326] i2cDumpI2c(): stage=3
[I][esp32-hal-i2c.c:327] i2cDumpI2c(): error=0
[I][esp32-hal-i2c.c:328] i2cDumpI2c(): event=0x3ffb8570 bits=0
[I][esp32-hal-i2c.c:329] i2cDumpI2c(): intr_handle=0x3ffb85a0
[I][esp32-hal-i2c.c:330] i2cDumpI2c(): dq=0x3ffb854c
[I][esp32-hal-i2c.c:331] i2cDumpI2c(): queueCount=1
[I][esp32-hal-i2c.c:332] i2cDumpI2c(): queuePos=0
[I][esp32-hal-i2c.c:333] i2cDumpI2c(): errorByteCnt=0
[I][esp32-hal-i2c.c:334] i2cDumpI2c(): errorQueue=0
[I][esp32-hal-i2c.c:335] i2cDumpI2c(): debugFlags=0x00000000
[I][esp32-hal-i2c.c:289] i2cDumpDqData(): [0] 7bit 41 R STOP buf@=0x3ffbfeb8, len=1, pos=0, ctrl=11110
[I][esp32-hal-i2c.c:307] i2cDumpDqData(): 0x0000: .                                00 
[I][esp32-hal-i2c.c:347] i2cDumpInts(): 0 row	count	INTR	TX	RX	Tick

Re: ESP32 I2C PCF8574 read issue

Posted: Mon Jul 01, 2019 2:15 pm
by jgustavoam
I have to enable the Debug bit in the Sketch. But I have not identified the error yet.
No error is being detected.

Code: Select all

void ReadData ()
{
  uint8_t flag = 1 << 1;                   // turn on bit 1
  uint32_t debugFlag = flag << 16;         // correctly position the 8bits of flag as the second byte of setBits.
  Wire.setDebugFlags(debugFlag, 0);        // resetBits=0 says leave all current setBits as is.

  Wire.begin();                   // Start I2C
  Wire.requestFrom(PCF8574, 1);   // Read One Byte from PCF8574
  pcfData = Wire.read();          // Byte Read

  Wire.setDebugFlags(0, debugFlag); // don't add any new debug, remove debugFlag
}
DEBUG LOG at Serial Console:

Code: Select all

rst:0x1 (POWERON_RESET),boot:0x17 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:928
ho 0 tail 12 room 4
load:0x40078000,len:8424
ho 0 tail 12 room 4
load:0x40080400,len:5868
entry 0x4008069c
[D][esp32-hal-i2c.c:1337] i2cProcQueue():  Busy Timeout start=0xd6, end=0xd6, =0, max=50 error=0
[E][esp32-hal-i2c.c:319] i2cDumpI2c(): i2c=0x3ffbebe0
[I][esp32-hal-i2c.c:320] i2cDumpI2c(): dev=0x60013000 date=0x16042000
[I][esp32-hal-i2c.c:322] i2cDumpI2c(): lock=0x3ffb84ec
[I][esp32-hal-i2c.c:324] i2cDumpI2c(): num=0
[I][esp32-hal-i2c.c:325] i2cDumpI2c(): mode=1
[I][esp32-hal-i2c.c:326] i2cDumpI2c(): stage=3
[I][esp32-hal-i2c.c:327] i2cDumpI2c(): error=0
[I][esp32-hal-i2c.c:328] i2cDumpI2c(): event=0x3ffb8570 bits=0
[I][esp32-hal-i2c.c:329] i2cDumpI2c(): intr_handle=0x3ffb85a0
[I][esp32-hal-i2c.c:330] i2cDumpI2c(): dq=0x3ffb854c
[I][esp32-hal-i2c.c:331] i2cDumpI2c(): queueCount=1
[I][esp32-hal-i2c.c:332] i2cDumpI2c(): queuePos=0
[I][esp32-hal-i2c.c:333] i2cDumpI2c(): errorByteCnt=0
[I][esp32-hal-i2c.c:334] i2cDumpI2c(): errorQueue=0
[I][esp32-hal-i2c.c:335] i2cDumpI2c(): debugFlags=0x00020000
[I][esp32-hal-i2c.c:289] i2cDumpDqData(): [0] 7bit 20 R STOP buf@=0x3ffbfeb8, len=1, pos=0, ctrl=11110
[I][esp32-hal-i2c.c:307] i2cDumpDqData(): 0x0000: .                                00 
[I][esp32-hal-i2c.c:347] i2cDumpInts(): 0 row	count	INTR	TX	RX	Tick 
[I][esp32-hal-i2c.c:438] i2cTriggerDumps(): after ProcQueue
[I][esp32-hal-i2c.c:347] i2cDumpInts(): 0 row	count	INTR	TX	RX	Tick

Re: ESP32 I2C PCF8574 read issue

Posted: Mon Jul 01, 2019 10:37 pm
by jgustavoam
Correcting important information!

I was able to do some ESP32 Voltmeter tests on my Laptop.
The Arduino IDE version is 1.8.5 and the CORE version 1.0.0.
The symptom is different, but it does not work either! Only now, Over Voltage does not appear.
The I2C interface still has a problem.

I remembered that the first version of Core I used was the previous version of 1.0.0.
And I used the old method to install the package:
Old method for installing ESP32 in the Arduino IDE:
https://github.com/espressif/arduino-es ... windows.md

I will try to recreate the environment I used when the project worked well.

Re: ESP32 I2C PCF8574 read issue

Posted: Tue Jul 02, 2019 2:27 am
by jgustavoam
Chuck (StickBreaker) helped me in Github and solved the problem!
I must change my Sketch.
https://github.com/espressif/arduino-esp32/issues/2949
Conclusion of Chuck :
Don't call Wire() from an interrupt context, Set a flag, then let the main loop do the work.