I2C question

53 views
Skip to first unread message

Ted Meyers

unread,
Aug 19, 2016, 4:23:01 PM8/19/16
to diyrovers
If I understand correctly, the right way to use I2C is to put in pullup resistors on the SDA and SCL to whatever logic voltage you want to use.  But, it seems like every breakout board (with I2C) that I buy has built in pullups.  That seems right if you are just connecting one, but what if you connect multiple boards and what if they pull up to different voltages?  Is that okay?  And should I use the internal pullups on my microcontroller?

Case in point: I have the ITG MPU6050/GY-521 (goes by different names, but it is a cheap IMU that is all over ebay).  The schematic that I found and my multimeter both say that it pulls to 3.3V.  It has a regulator and takes 5V on VIN, but is 3.3V.  It works on both a teensy 3.0 and an UNO.  The Adafruit BNO055 is similar in that it has a 5V regulator and is 3.3V and works on both previously mentioned microcontrollers.  But it also has logic level shifters on the I2C pins (I can't figure the schematic -- it has 2 sections, one that says the pins are pulled to 3.3V and another that says the same I2C pins are pulled to 5V -- my voltmeter says 5V though).  Adafruit says it will work on 3.3V microcontrollers, and it does, even with pins that are not 5V tolerant.

Third point is my LCD screen with an I2C backpack.  There is nothing on this guy indicating that it is anything but 5V, and my voltmeter agrees.  Yet, it also works with the Teensy 3.0 (not 5V tolerant).  Also, I was able to plug all 3 of these boards into the teensy and get them all working at the same time.  Weird thing was that when I did this, the voltmeter said the I2C lines were at 3.3V.  Clearly, there is something going on here that I very much do not understand.  Can anyone explain this?  And am I doing something bad to my teensy?  (I just need to get the 3,2 -- it has 5V tolerant pins!)

Ted

Jon Watte

unread,
Aug 19, 2016, 5:19:25 PM8/19/16
to diyrovers
In general, multiple pull-ups are discouraged on the I2C bus. Also, I2C is defined in terms of current-when-held-down, rather than voltage, and IIRC, it's 2 mA. So, a 5V system needs 2.2 kOhm pull-ups; a 3.3V system needs 1.5 kOhm pull-ups. But I didn't go back and verify this, so it could be wrong.

However, there is some sense in putting at least a weakish pull-up (5k-10k) on each device, as this will compensate for the additional capacitive loading that each I2C bus input causes. If you have one central pull-up of 2.2k and multiple weak pull-ups, one on each device, then that will tend to "auto-compensate" for more loading to some extent.
If you run the signals further, and worry about ringing and reflective waves, you have to do a totally different analysis though.

What will physically happen when you connect multiple pull-ups, to different voltages?
The pull-ups will form a resistive ladder. You will have one node at 3.3V, resistor 1.5k Ohm (or whatever,) bus, resistor 2.2 kOhm (or whatever,) 5.0V.
Ohm's law says the bus will be held at 3.3V + (5.0V-3.3V)*(1.5k/(1.5k+2.2k) or about 4.0 Volts (3.98V)

Are your 3.3V units tolerant of 4.0V plus whatever ringing may happen? If not, that would be a bad idea.

I2C is most easily voltage translated using a pair of MOSFET transistors with a pull-up on each side. (one MOSFET each for SCL and SDA.)
The circuit is super simple and easily findable with a google search.

Sincerely,

jw






Sincerely,

Jon Watte


--
"I find that the harder I work, the more luck I seem to have." -- Thomas Jefferson

--
You received this message because you are subscribed to the Google Groups "diyrovers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to diyrovers+unsubscribe@googlegroups.com.
To post to this group, send email to diyr...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/diyrovers/a5b19bd9-3202-458d-959b-b6f559236f35%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jon Watte

unread,
Aug 19, 2016, 5:22:19 PM8/19/16
to diyrovers
Oh, also regarding your observed "nothing burns up" behavior:
Because the resistors limit how much current is being drawn, it may be that the input ESD Zeners on the 3.3V pins dissipate the additional voltage.
Generally, they are only rated to do this for very brief spikes, but if the current is low enough (how strong are the 5.0V pull-ups?) then they may be able to do this for longer.
You'd be technically out of spec, but perhaps not at a high enough current that it causes damage. Or maybe it just slowly eats away at the Zener junction and you'll find a failed chip sometime in the future. We really can't know for sure :-(

Sincerely,

jw





Sincerely,

Jon Watte


--
"I find that the harder I work, the more luck I seem to have." -- Thomas Jefferson

Ted Meyers

unread,
Aug 19, 2016, 7:04:13 PM8/19/16
to diyrovers
Ah cool, this is very informative.  The MPU6050 has 4.7K to 3.3V, the BNO055 has 10K on the 3.3V side and 10K on the 5V pullup side (with some sort of transister-diode thing in-between, and the LCD backpack is 4.7K to 5V.  I measured the voltage with everything on the bus and it appears to be around 3.8V.  I'm guessing that it is low enough and the current is low enough that everything is ok, need to do some calculations though.  Thanks for the great info!

Ted
To unsubscribe from this group and stop receiving emails from it, send an email to diyrovers+...@googlegroups.com.

Jon Watte

unread,
Aug 19, 2016, 8:18:46 PM8/19/16
to diyrovers
with some sort of transister-diode thing in-between

I bet that's a MOSFET doing level translation!
The Arduino site actually have a good diagram of this:

Sincerely,

jw





Sincerely,

Jon Watte


--
"I find that the harder I work, the more luck I seem to have." -- Thomas Jefferson

To unsubscribe from this group and stop receiving emails from it, send an email to diyrovers+unsubscribe@googlegroups.com.

To post to this group, send email to diyr...@googlegroups.com.

Ted Meyers

unread,
Aug 19, 2016, 11:27:30 PM8/19/16
to diyrovers
Hah, you are good!  That is almost exactly the same circuit as what I was looking at: https://learn.adafruit.com/assets/24546

Yeah, I still have a lot to learn about hardware...

Jon Russell

unread,
Aug 20, 2016, 9:04:27 PM8/20/16
to diyrovers
Speaking of which ... I am trying to get a BNO055 working with an mBed but I can't get either of the libraries I found to work. I read there are issues with clock stretching with some microcontrollers ? Has anyone else had trouble with an mBed ?

I can't even get the ID ...

thanks

Jon.

Ted Meyers

unread,
Aug 26, 2016, 11:10:42 AM8/26/16
to diyrovers
I don't know about mBed, is it 3.3V?  Are you using a 5V breakout board with level shifters like the Adafruit board (ok, realize that I don't know what I'm talking about here -- software guy -- and I may be saying something stupid).  Anyway, I've used the adafruit board with logic shifters and a raw 3.3V board successfully on 5V and 3.3V arduinos and a teensy, so I don't know why it wouldn't work on an mbed.  Make sure that you use the right ID; you might try programming an arduino to scan for the ID, at least that would give you a starting point.

jesse brockmann

unread,
Aug 26, 2016, 11:49:06 AM8/26/16
to diyr...@googlegroups.com
Jon,
   Dunno, what class you running in?  LOL.  I kid.

Clock stretching can sometime cause a multibyte reads to fail, but I've not seen it cause issues in not responding at all.  So, I'd suggest something else is going on.   Have you used other i2c devices with mBed?   I've used both a pi, and a teensy to talk to BNO-055 at 100khz and 400khz without issues.  Keep your cables short.

Jesse

--
You received this message because you are subscribed to the Google Groups "diyrovers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to diyrovers+unsubscribe@googlegroups.com.

To post to this group, send email to diyr...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages