1
\$\begingroup\$

I am using I2C communication with the ESP32 as the master.

Do I need pull-up/pull-down resistors on the SDA and SCL lines?

I could not find anything on the datasheet that said whether there were internal pull-up/pull-down resistors.

Links to datasheets:

https://www.espressif.com/sites/default/files/documentation/esp32_datasheet_en.pdf

https://www.espressif.com/sites/default/files/documentation/esp32-wroom-32e_esp32-wroom-32ue_datasheet_en.pdf

\$\endgroup\$
8
  • 1
    \$\begingroup\$ You need external pull up resistors. I don’t know of any chip that implements I2C that has internal pullups of the required value. \$\endgroup\$
    – Kartman
    Commented Dec 30, 2021 at 20:59
  • \$\begingroup\$ What is a good pull-up resistor value? 4.7k? 10k? \$\endgroup\$ Commented Dec 30, 2021 at 21:04
  • 2
    \$\begingroup\$ You’ve not read the I2C specification then. I’d suggest you give it a read. For 3V3 circuit, I’d be leaning towards 2k2. Not super critical. \$\endgroup\$
    – Kartman
    Commented Dec 30, 2021 at 21:06
  • \$\begingroup\$ Are you talking about the datasheet for the ESP32 or some other specification? Could you link the specification for me please. \$\endgroup\$ Commented Dec 30, 2021 at 21:10
  • 4
    \$\begingroup\$ Google i2c specification. First hit was the nxp pdf. \$\endgroup\$
    – Kartman
    Commented Dec 30, 2021 at 21:16

4 Answers 4

3
\$\begingroup\$

Do I need pull-up/pull-down resistors on the SDA and SCL lines?

Yes. 2k2-3k3 is fine.

If you're using one of the off-the-shelf I2C peripherals like the LCD display, IO expanders, etc then warning: most of them require 5V, and ESP32 runs on 3V3.

You must not connect the pullups on the ESP side to +5V, but to 3V3!

I've been using this simple voltage translation schematic with success:

enter image description here

"2.5V" on the left should be 3V3, of course, and the gpio numbers are wrong, but you get the idea. You can use any N MOSFET with low capacitance and threshold Vgs such that it turns on properly when about 3V Vgs. The easiest way is to search for MOSFETs with RdsON of a few ohms or tens of ohms, specified at Vgs of 2.5, and sort by price. Here's the one I'm using. Also very neat for driving loads from a 3V3 GPIO.

Since you now have two pullups on each line instead of one, it's a good idea to double the resistor value to get the same current, so 4k7 instead of 2k2 for example.

\$\endgroup\$
3
\$\begingroup\$

As they are GPIO pins unless specifically configured to use I2C, yes, you do need pull-up resistors.

Even if you can turn on internal pull-up resistors, it might be fine for lows speed communication, but in practice they are usually too high resistance for any real use in I2C.

\$\endgroup\$
2
\$\begingroup\$

As a rule of thumb I2C bus always requires 2 external pull-up resistors for the SDA & SCL lines.

Their values would depend on bus speed, voltage & capacitance (which includes both wires/trace & devices capacitance). Good starting point are usually ~2.2K for 400 kHz and 3.3V bus with a few slaves on the bus and when all are located on the same small board.

For more information on bus capacitance & resistor value calculation you can refer to this question: Is there a correct resistance value for I2C pull-up resistors?

\$\endgroup\$
0
\$\begingroup\$

TI has written a paper that precisely calculates the minimum and maximum values of both clock and data lines pullup resistors. These depend on the input and bus capacitances used and the supply voltage. There is no so-called rule of thumb for this!

Link to the paper: https://www.ti.com/lit/an/slva689/slva689.pdf

\$\endgroup\$
1
  • \$\begingroup\$ That paper is just a simplified version of the calculations in the official I2C specs and it does not deal with some corner cases, such as the case which ends up min and max values showing you can't even use resistors but need a current source. Also the question wasn't how to calculate their exact value (which is often unnecessary) but if they are needed at all (some MCU boards provide them for you, some don't). \$\endgroup\$
    – Justme
    Commented Jun 21 at 9:15

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.