0
\$\begingroup\$

i'm trying to read a I2C HTU21D from this breakout (schematics below) temperature and humidity sensor and send data to an mqtt broker.

enter image description here

I'm using PCA9306 in order to use 5V and go "far" (30m) from the main MCU PCB using CAT5E cable and RJ45 connectors.

The MCU circuit is very simple, one HTU21D, a PCA9306, 30 meters of cable cat5e and a ESP32-POE-ISO with another PCA9306.

The two PCA are used in order to go with 5V in SCL and SDA bus lines.

The cable has a capacitance of 56pf/m, so five meters are 1680pf in total, higher than the maximum I2C limit of 400pf.

I've used my logic analyzer to investigate and it seems that when i plug LAN to the ESP32-POE-ISO there are some logic spikes on I2C lines that produces those wrong measurements, tomorrow i'll post some screen of my oscilloscope

I'm using Arduino with the latest Espressif 1.0.4 Library.

The I2C bus speed is 10khz and there are external pull-up resistor of 10k on I2C bus (ESP32 side) and 330ohm pull-up resistors on the PCA9306 bus side.

Here is the schematic:

Schematic

EDIT: 27/07/2020 - changed pull up resistors and added oscilloscope traces

I've replaced the pull-up resistors from 330ohm (as suggested) to 2k2ohm, here is the result:

Scope trace of 330ohm pull up resistors (SCL - CH1): As you can see, the clock waveform is really sharpen, and has around 340mV of delta from 0V (i think that this could be a problem) - In this scenario, data reading works but it's unstable: like 10 measurements wrong every 100, 330ohm

Scope trace of 2k2ohm pull up resistors (SCL - CH1): As you can see, the clock waveform is a nice square looking signal and there isn't any delta from 0V, in this scenario the data reading works very unstable: 40 measurements wrong every 100 enter image description here

Any suggestion to solve that issue?

\$\endgroup\$
7
  • \$\begingroup\$ Try reducing the size of those pull up resistors to 2.2kOhm. \$\endgroup\$
    – vicatcu
    Commented Jul 26, 2020 at 18:15
  • \$\begingroup\$ You think that the bus needs only strong pull-up resistors? This is very strange, the problem seems "random", maybe it's related? \$\endgroup\$
    – VirtApp
    Commented Jul 26, 2020 at 18:52
  • \$\begingroup\$ 90+% of the problems with i2c come down to that... your logic analyzer hides the true shape of the waveform. \$\endgroup\$
    – vicatcu
    Commented Jul 26, 2020 at 19:50
  • 1
    \$\begingroup\$ 330 ohm pull-ups to 5V? That's 15mA of current. That is a ridiculous value for a 10kHz I2C bus, it violates the 3mA limit fivefold. \$\endgroup\$
    – Justme
    Commented Jul 26, 2020 at 22:13
  • 1
    \$\begingroup\$ If you think that this will be an issue, I'll try tomorrow to replace them with 2.2k! \$\endgroup\$
    – VirtApp
    Commented Jul 26, 2020 at 22:21

1 Answer 1

1
\$\begingroup\$

The sensor can drive the i2C bus at up to 4mA as said in the datasheet. The 330 ohm pullups are far too strong for the sensor. The Adafruit module provides 10k pullups to 3.3V, and level shifting with 10k pullups to 5V. That is below 1mA, so the remaining pullups must only add up to 2-3mA. This means that the PCA 5V side does not need pullups as there is already pullups on the sensor 5V side, but you can put 1-2mA pullups there. The 3.3V side of PCA needs also pullups if the ESP does not provide them.

\$\endgroup\$
6
  • \$\begingroup\$ I've added scope traces :) \$\endgroup\$
    – VirtApp
    Commented Jul 27, 2020 at 8:07
  • \$\begingroup\$ I apologize for the confusion...i've added the right schematic of the sensor breakout, the problem still persists, any toughts? \$\endgroup\$
    – VirtApp
    Commented Jul 27, 2020 at 15:15
  • \$\begingroup\$ So now you have increased the cable length and have now 1680pF capacitance? The clock and data edges will be slow. Even if the clock rate is slow, the MCU must wait for longer after clock release to sample data reliably. Based on scope pictures, about 10us. If the I2C hardware sample point can't be delayed, perhaps switch to software I2C. You do have clock/ground and data/ground pairs? \$\endgroup\$
    – Justme
    Commented Jul 27, 2020 at 17:17
  • \$\begingroup\$ Yes, i've calculated the right lenght of the cable, so 1680pF capacitance...How i can "wait" for SCL and SDA on the ESP32? What you mean for clock/ground and data/ground pairs? \$\endgroup\$
    – VirtApp
    Commented Jul 27, 2020 at 18:27
  • \$\begingroup\$ I don't know anything about how ESP32 I2C works. Some MCUs have controllable timing parameters, some don't. They can be instructed that the bus has slow rise time so they don't sample it too early. Cat5 has signal pairs, for best results you must use one pair for clock and ground and another pair for data and ground, you can't use the same pair for clock and data or they will interfere. \$\endgroup\$
    – Justme
    Commented Jul 27, 2020 at 18:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.