0

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

RGB Engineer
  • 808
  • 4
  • 19
  • 1
    You need external pull up resistors. I don’t know of any chip that implements I2C that has internal pullups of the required value. – Kartman Dec 30 '21 at 20:59
  • What is a good pull-up resistor value? 4.7k? 10k? – RGB Engineer Dec 30 '21 at 21:04
  • 1
    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. – Kartman Dec 30 '21 at 21:06
  • Are you talking about the datasheet for the ESP32 or some other specification? Could you link the specification for me please. – RGB Engineer Dec 30 '21 at 21:10
  • 3
    Google i2c specification. First hit was the nxp pdf. – Kartman Dec 30 '21 at 21:16
  • @Kartman why should someone have to read the entire I2C specification just to get a range of reasonable values? That makes as much sense to me as asking people to read an ampacity chart before they hook up their I2C lines. Only a tiny sliver of humanity needs to concern themselves with these minute details, and it's not a good look for us to be snobbish to those who can just get a number and move on with their lives. – Kenn Sebesta Jul 13 '23 at 21:17
  • @KennSebesta, you’ve somehow read a whole lot more into a simple comment than what I’d anticipated. The nxp spec is THE reference and addresses the question precisely. Whether one reads the relevant sections or the whole document is a personal choice. Besides, it’s not a huge tome.Step back and consider if you added any value to the question rather than acting on impulse based on an overly literal interpretation. My medication helps me a lot to suppress such impulses. And you are late to the party! – Kartman Jul 14 '23 at 14:01
  • @Kartman I believe we add value when we push back against gatekeeping. 'nuff said. – Kenn Sebesta Jul 15 '23 at 03:37

3 Answers3

2

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.

Justme
  • 127,425
  • 3
  • 97
  • 261
1

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?

NStorm
  • 1,889
  • 12
  • 23
1

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.

bobflux
  • 70,433
  • 3
  • 83
  • 203