rickseiden
Posts: 411
Joined: Thu Aug 02, 2012 12:21 pm
Location: Buffalo, NY, USA

Does i2c need pullups (resistors, not diapers!)

Sat Dec 28, 2013 6:39 pm

I've been looking around the internet, and I've seen some i2c diagrams use 2 10k resistors to pull up the SDL and SDA lines to Vcc.

I've done some prototyping with i2c, but never installed these resistors, and never had any problems. But I'm looking at taking one of my creations to a full time, in use, circuit. Soldered and everything.

Before I do that, I'd like to make sure I get everything right. So, are they necessary?

Thanks
Rick
There are 10 types of people in this world. Those that understand binary, and those that don't.

User avatar
joan
Posts: 14074
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Does i2c need pullups (resistors, not diapers!)

Sat Dec 28, 2013 6:45 pm

I believe the answer to be yes, the resistors are necessary. The Pi's SDA and SCL lines have physical resistors on the board to pull up to 3.3V.

rickseiden
Posts: 411
Joined: Thu Aug 02, 2012 12:21 pm
Location: Buffalo, NY, USA

Re: Does i2c need pullups (resistors, not diapers!)

Sat Dec 28, 2013 6:47 pm

joan wrote:I believe the answer to be yes, the resistors are necessary. The Pi's SDA and SCL lines have physical resistors on the board to pull up to 3.3V.
That would explain why I haven't needed them. I've only done I2C from the RPi, and they are already there.

Thanks!
There are 10 types of people in this world. Those that understand binary, and those that don't.

User avatar
Richard-TX
Posts: 1549
Joined: Tue May 28, 2013 3:24 pm
Location: North Texas

Re: Does i2c need pullups (resistors, not diapers!)

Sun Dec 29, 2013 6:02 pm

rickseiden wrote:
joan wrote:I believe the answer to be yes, the resistors are necessary. The Pi's SDA and SCL lines have physical resistors on the board to pull up to 3.3V.
That would explain why I haven't needed them. I've only done I2C from the RPi, and they are already there.

Thanks!

While you don't necessarily need 10k pullups, if you expect to have cable length of any distance, each chip should have it's own pullups. Want to have 10 ft or more of cable? Use CAT6 network cable and assign the signals as follows: I have driven the I2C bus to I2C Plus speeds without issue provided each chip has it's own pullups and 568B patch cables are used.

Image

Here is an example of what can be done using RJ45 connectors.

Image
right click and "view image" for larger picture.
Richard
Doing Unix since 1985.
The 9-25-2013 image of Wheezy can be found at:
http://downloads.raspberrypi.org/raspbian/images/raspbian-2013-09-27/2013-09-25-wheezy-raspbian.zip

rickseiden
Posts: 411
Joined: Thu Aug 02, 2012 12:21 pm
Location: Buffalo, NY, USA

Re: Does i2c need pullups (resistors, not diapers!)

Sun Dec 29, 2013 8:14 pm

The distance I'm covering is inches, if that much. I just did some work with my GertBoard and I2C, and forgot to put the pull-up resistors in place. It worked just fine. Now I'm more confused then ever!
There are 10 types of people in this world. Those that understand binary, and those that don't.

User avatar
Gert van Loo
Posts: 2482
Joined: Tue Aug 02, 2011 7:27 am
Contact: Website

Re: Does i2c need pullups (resistors, not diapers!)

Sun Dec 29, 2013 8:33 pm

An I2C interface MUST have pull-up resistors. The value of those depend on the voltage and the speed you plan to run at.
The Raspberry-Pi already has pull-up resistor on the board so you don't have to add any more.
That is if you connect to the Pi!

But!! If you ever make your own I2C bus you must add pull-up resistors.
e.g. from the Atmega on the Gertboard to a I2c device other then the Pi.

Note that some controllers have internal pull-up resistors on the I/O pins which you can program to be on.
Those are not suited to be used as I2C pull up resistors as they are often too weak.

rickseiden
Posts: 411
Joined: Thu Aug 02, 2012 12:21 pm
Location: Buffalo, NY, USA

Re: Does i2c need pullups (resistors, not diapers!)

Sun Dec 29, 2013 8:45 pm

Gert van Loo wrote:An I2C interface MUST have pull-up resistors. The value of those depend on the voltage and the speed you plan to run at.
The Raspberry-Pi already has pull-up resistor on the board so you don't have to add any more.
That is if you connect to the Pi!

But!! If you ever make your own I2C bus you must add pull-up resistors.
e.g. from the Atmega on the Gertboard to a I2c device other then the Pi.

Note that some controllers have internal pull-up resistors on the I/O pins which you can program to be on.
Those are not suited to be used as I2C pull up resistors as they are often too weak.
Gert, I'm humbled that you weighed in on this! My design right now is from the ATMega 328P on my GertBoard to an MCP23017. I plan on eventually replacing the ATMega with an ATTiny85, if I can. I plan on running the circuit at 5V. How would I calculate the correct resistance on those pull-ups?

Thanks,
Rick
There are 10 types of people in this world. Those that understand binary, and those that don't.

User avatar
Richard-TX
Posts: 1549
Joined: Tue May 28, 2013 3:24 pm
Location: North Texas

Re: Does i2c need pullups (resistors, not diapers!)

Sun Dec 29, 2013 10:54 pm

Just put 10 k resistors between SDA and SCL and VDD with every chip you add to the bus.
Richard
Doing Unix since 1985.
The 9-25-2013 image of Wheezy can be found at:
http://downloads.raspberrypi.org/raspbian/images/raspbian-2013-09-27/2013-09-25-wheezy-raspbian.zip

rickseiden
Posts: 411
Joined: Thu Aug 02, 2012 12:21 pm
Location: Buffalo, NY, USA

Re: Does i2c need pullups (resistors, not diapers!)

Sun Dec 29, 2013 10:58 pm

I was reading the data sheet on the MCP23017, which I don't fully understand, and trying to compute the pull up value based on this. I came up with the notion that the pull ups had to be greater than 900 ohms, and less then 885 ohms. Obviously, I did something wrong. But I noticed that the data sheet calls specifically for a pull up of 1k ohm, and a capacitor connected between SDA/SDL and ground of 135pF.

So now I need pull up resistors, and "pull down capacitors"?
There are 10 types of people in this world. Those that understand binary, and those that don't.

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 12010
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: Does i2c need pullups (resistors, not diapers!)

Sun Dec 29, 2013 11:16 pm

the pull ups had to be greater than 900 ohms, and less then 885 ohms.
Does not compute!

No value is >900 and <885
The reverse would be possible >885 and <900, but even in that sense, you are talking about a ridiculously precise resistance value. no need for that at all!

The PI's pull-up's are 1800 Ohm, and that is about optimal, its the "strongest" pull-up the PI can still reliably pull down with normal driver strength settings (1.8333 mA) Its possible to use stronger pullups, but normally that isn't needed. If there are still problems with these pullups, then the problem isn't the pullups, but in all probability pulling up to 3,3V doesn't fulfill some minimal logic high level demand somewhere, or there is a problem with clock stretching.

capacitors are not needed or wanted to add, what is probably meant is the maximum parachutic capacitance the wiring may have.

You looking far too deep into this, the pullups are ideal, and are most probably not the culprit.
But simply forgetting the pullups, and having it "work" because GPIO's often have weak pullups (around 50K) -that- is sometimes a problem, the exact value of the pullups almost never is, unless you are talking about optimalisation needed because of very long wiring.

rickseiden
Posts: 411
Joined: Thu Aug 02, 2012 12:21 pm
Location: Buffalo, NY, USA

Re: Does i2c need pullups (resistors, not diapers!)

Sun Dec 29, 2013 11:25 pm

mahjongg wrote:
the pull ups had to be greater than 900 ohms, and less then 885 ohms.
Does not compute!

No value is >900 and <885
[/quote]

My point exactly!
mahjongg wrote:The PI's pull-up's are 1800 Ohm, and that is about optimal, its the "strongest" pull-up the PI can still reliably pull down with normal driver strength settings (1.8333 mA) Its possible to use stronger pullups, but normally that isn't needed. If there are still problems with these pullups, then the problem isn't the pullups, but in all probability pulling up to 3,3V doesn't fulfill some minimal logic high level demand somewhere, or there is a problem with clock stretching.
I'm looking to take the circuit off the RPi eventually (it's actually on the AVR on the GertBoard right now, so technically it is already off the RPi). That's why I need to compute the values of these things.

As an aside, I just read at Adafruit that you can power the MCP23017 with 5V, and still hook it up to the 3v3 i2c lines of the RPi because of the internal pull-up resistors. As I only have one RPi, I'm not going to try this any time soon.
There are 10 types of people in this world. Those that understand binary, and those that don't.

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 12010
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: Does i2c need pullups (resistors, not diapers!)

Sun Dec 29, 2013 11:39 pm

That's why I need to compute the values of these things.
No, you normally do not need to compute the value of these pullups, just use a value around 2K2, (1K to 10K) and it should work fine, provided that all devices use the same kind of ViH and ViL levels, which is normally the case when they use the same VCC voltage, but NOT if one uses 3V3 and the other 5V! In that case the only generic solution is using level shifters. Tweaking the pull-up value does almost nothing to remedy that problem.

User avatar
Richard-TX
Posts: 1549
Joined: Tue May 28, 2013 3:24 pm
Location: North Texas

Re: Does i2c need pullups (resistors, not diapers!)

Mon Dec 30, 2013 1:03 am

Take a look at what Adafruit does with their 16 port i2c based led/servo controller.

Another way to look at it is that if Adafruit uses 10k ohm resistors and 32 of their devices can be placed on a I2C bus, then 10k must be about right.

Image
right click and "view image" for full size
Richard
Doing Unix since 1985.
The 9-25-2013 image of Wheezy can be found at:
http://downloads.raspberrypi.org/raspbian/images/raspbian-2013-09-27/2013-09-25-wheezy-raspbian.zip

User avatar
Gert van Loo
Posts: 2482
Joined: Tue Aug 02, 2011 7:27 am
Contact: Website

Re: Does i2c need pullups (resistors, not diapers!)

Mon Dec 30, 2013 7:19 am

My estimate is that 10K is too high for a 400KHz I2C bus.
I use ~2K for 3V3 and ~3K for 5V.

User avatar
FTrevorGowen
Forum Moderator
Forum Moderator
Posts: 4992
Joined: Mon Mar 04, 2013 6:12 pm
Location: Bristol, U.K.
Contact: Website

Re: Does i2c need pullups (resistors, not diapers!)

Mon Dec 30, 2013 6:47 pm

rickseiden wrote: ...
As an aside, I just read at Adafruit that you can power the MCP23017 with 5V, and still hook it up to the 3v3 i2c lines of the RPi because of the internal pull-up resistors. As I only have one RPi, I'm not going to try this any time soon.
As a (further) aside, my first I2C test circuits were based upon Ciseco's "Slice of PI/O" board (based upon Nathan Chantrell's project)** using an MCP23017 powered by 5V to drive a LED bargraph display or an ex-Sinclair Cambridge calculator display*** w/o problems (and Nathan links to an explanation of why it's O.K. to do this, IIRC).
Trev.
** http://shop.ciseco.co.uk/k002-slice-of-pi-o/
*** http://www.cpmspectrepi.webspace.virgin ... OfPio.html
Still running Raspbian Jessie on some older Pi's (an A, B1, B2, B+, P2B, 3xP0, P0W) but Stretch on my 2xP3A+, P3B+, P3B, B+, A+ and a B2. See: https://www.cpmspectrepi.uk/raspberry_pi/raspiidx.htm

rickseiden
Posts: 411
Joined: Thu Aug 02, 2012 12:21 pm
Location: Buffalo, NY, USA

Re: Does i2c need pullups (resistors, not diapers!)

Mon Dec 30, 2013 6:53 pm

FTrevorGowen wrote:
rickseiden wrote: ...
As an aside, I just read at Adafruit that you can power the MCP23017 with 5V, and still hook it up to the 3v3 i2c lines of the RPi because of the internal pull-up resistors. As I only have one RPi, I'm not going to try this any time soon.
As a (further) aside, my first I2C test circuits were based upon Ciseco's "Slice of PI/O" board (based upon Nathan Chantrell's project)** using an MCP23017 powered by 5V to drive a LED bargraph display or an ex-Sinclair Cambridge calculator display*** w/o problems (and Nathan links to an explanation of why it's O.K. to do this, IIRC).
Trev.
Trev, You're the second person who's said that it will work. I think that I've had two or three people tell me not to do it under any circumstances, too. I want a bidirectional level shifter, and will be picking one up from Adafruit eventually. Until then, I'm not gonna take the chance. Success stories and all. I'm just to a-scared!
There are 10 types of people in this world. Those that understand binary, and those that don't.

User avatar
Douglas6
Posts: 4710
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Does i2c need pullups (resistors, not diapers!)

Mon Dec 30, 2013 7:03 pm

rickseiden wrote:As an aside, I just read at Adafruit that you can power the MCP23017 with 5V, and still hook it up to the 3v3 i2c lines of the RPi because of the internal pull-up resistors. As I only have one RPi, I'm not going to try this any time soon.
Not knowing any better, I trusted LadyAda on this one, and did this exactly on several circuits. No smoke yet. I believe this is how her 16x2 LCD Pi plate is wired, and there's lots of those out there.
Last edited by Douglas6 on Mon Dec 30, 2013 7:26 pm, edited 1 time in total.

User avatar
Richard-TX
Posts: 1549
Joined: Tue May 28, 2013 3:24 pm
Location: North Texas

Re: Does i2c need pullups (resistors, not diapers!)

Mon Dec 30, 2013 7:10 pm

Gert van Loo wrote:My estimate is that 10K is too high for a 400KHz I2C bus.
I use ~2K for 3V3 and ~3K for 5V.
I have used 10k with the Rpi I2c bus at 1 Mhz speeds (Fast Mode +) with no issues.

Cables have to be Cat5/6, the SDA and SCL signals have to be a twisted pair with ground but other than that no special considerations are warranted. See picture below for one example. I chose this scheme as nothing will get blown up if the wiring is reversed. It won't work if reversed, but nothing will get damaged.

Image

http://www.nxp.com/documents/leaflet/75015806.pdf
Richard
Doing Unix since 1985.
The 9-25-2013 image of Wheezy can be found at:
http://downloads.raspberrypi.org/raspbian/images/raspbian-2013-09-27/2013-09-25-wheezy-raspbian.zip

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 12010
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: Does i2c need pullups (resistors, not diapers!)

Mon Dec 30, 2013 8:46 pm

most of the issues occur when the I2C device expects a logic high that is higher than 3.3V. For example many 5V logic devices expect a minimum high level of 70% of their VCC, that is for a 5V powered device 5.0 * 0.7 = 3.5V.

rickseiden
Posts: 411
Joined: Thu Aug 02, 2012 12:21 pm
Location: Buffalo, NY, USA

Re: Does i2c need pullups (resistors, not diapers!)

Mon Dec 30, 2013 9:28 pm

mahjongg wrote:most of the issues occur when the I2C device expects a logic high that is higher than 3.3V. For example many 5V logic devices expect a minimum high level of 70% of their VCC, that is for a 5V powered device 5.0 * 0.7 = 3.5V.
Does that mean that no harm will come to the RPi if I hook up an I2C device powered at 5V to the I2C on my RPi, and that it potentially just won't work? Or is my RPi at risk doing this?
There are 10 types of people in this world. Those that understand binary, and those that don't.

User avatar
Richard-TX
Posts: 1549
Joined: Tue May 28, 2013 3:24 pm
Location: North Texas

Re: Does i2c need pullups (resistors, not diapers!)

Mon Dec 30, 2013 9:51 pm

When dealing with I2c devices it is indeed important to make sure that the specs of the device are adhered to. Some devices want a VDD of 5 volts, others like the PCA9685 will take anything from 2.3 to 5.5 volts, etc.

In the case of the PCA9544 mux, different buses with different voltages can be mixed.
Having said all that all of the I2c chips I have checks use a absolute value of 0.2 volts or lower to indicate a logic low on the I2c bus. I have never seen it be a percentage but I lead a sheltered life. :)
Richard
Doing Unix since 1985.
The 9-25-2013 image of Wheezy can be found at:
http://downloads.raspberrypi.org/raspbian/images/raspbian-2013-09-27/2013-09-25-wheezy-raspbian.zip

User avatar
FTrevorGowen
Forum Moderator
Forum Moderator
Posts: 4992
Joined: Mon Mar 04, 2013 6:12 pm
Location: Bristol, U.K.
Contact: Website

Re: Does i2c need pullups (resistors, not diapers!)

Mon Dec 30, 2013 10:03 pm

rickseiden wrote:
mahjongg wrote:most of the issues occur when the I2C device expects a logic high that is higher than 3.3V. For example many 5V logic devices expect a minimum high level of 70% of their VCC, that is for a 5V powered device 5.0 * 0.7 = 3.5V.
Does that mean that no harm will come to the RPi if I hook up an I2C device powered at 5V to the I2C on my RPi, and that it potentially just won't work? Or is my RPi at risk doing this?
Hi again, Rick - for reference here's the link to Nathan Chantrell's discussion of "why it's O.K. (for the Pi)":
http://nathan.chantrell.net/20120610/ra ... t-voltage/
In essence it's because the I2C buses are [should be] open-drain based. Having used the (loosely) equivalent "open-collector" methods many-many-moons ago I'm fairly confident that one, closely-connected device is fine, but, as Nathan also suggests, I have used (adafruit's "i2c safe") bi-directional level-shifters on circuits using more than one I2C device (eg: http://www.cpmspectrepi.webspace.virgin ... blePi.html and
http://www.cpmspectrepi.webspace.virgin ... oFull.html )
Trev.

Edit: Link corrected (or make sure you pasted what you thought you had :oops: )
Still running Raspbian Jessie on some older Pi's (an A, B1, B2, B+, P2B, 3xP0, P0W) but Stretch on my 2xP3A+, P3B+, P3B, B+, A+ and a B2. See: https://www.cpmspectrepi.uk/raspberry_pi/raspiidx.htm

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 12010
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: Does i2c need pullups (resistors, not diapers!)

Tue Dec 31, 2013 10:32 am

rickseiden wrote:
mahjongg wrote:most of the issues occur when the I2C device expects a logic high that is higher than 3.3V. For example many 5V logic devices expect a minimum high level of 70% of their VCC, that is for a 5V powered device 5.0 * 0.7 = 3.5V.
Does that mean that no harm will come to the RPi if I hook up an I2C device powered at 5V to the I2C on my RPi, and that it potentially just won't work? Or is my RPi at risk doing this?
As long as you only use pullups to 3V3 no harm will come to the PI, but some devices demand a pullup to 5V. That's where levels shifters come in, to split the I2C bus into a 3V3 and a 5V part!

User avatar
Richard-TX
Posts: 1549
Joined: Tue May 28, 2013 3:24 pm
Location: North Texas

Re: Does i2c need pullups (resistors, not diapers!)

Tue Dec 31, 2013 3:34 pm

Agreed and good advice. Know what you are doing when playing with +5 volts.
Richard
Doing Unix since 1985.
The 9-25-2013 image of Wheezy can be found at:
http://downloads.raspberrypi.org/raspbian/images/raspbian-2013-09-27/2013-09-25-wheezy-raspbian.zip

User avatar
dentex
Posts: 180
Joined: Sun May 20, 2012 7:58 am
Location: Italy
Contact: Website

Re: Does i2c need pullups (resistors, not diapers!)

Sun Sep 11, 2016 7:27 am

mahjongg wrote:
rickseiden wrote:
mahjongg wrote:most of the issues occur when the I2C device expects a logic high that is higher than 3.3V. For example many 5V logic devices expect a minimum high level of 70% of their VCC, that is for a 5V powered device 5.0 * 0.7 = 3.5V.
Does that mean that no harm will come to the RPi if I hook up an I2C device powered at 5V to the I2C on my RPi, and that it potentially just won't work? Or is my RPi at risk doing this?
As long as you only use pullups to 3V3 no harm will come to the PI, but some devices demand a pullup to 5V. That's where levels shifters come in, to split the I2C bus into a 3V3 and a 5V part!
Hello.
I'm trying to understand which is the correct wiring for a 16x2 and a 20x4 LCD screens I have.

How can I check if I'm in the right situation and I'm not risking to damage the RPi, with reference to the above post?

I added some more info on this LCD here:
viewtopic.php?p=1035575#p1035575

Thanks.
One of my projects with the Raspberry Pi:
--------------------------------------------------------
(Raspberry) Pi Aquarium Controller: https://github.com/dentex/piac
...and its dashboard: https://freeboard.io/board/O17ACD

Return to “Interfacing (DSI, CSI, I2C, etc.)”