go away spammer

Author Topic: I2C woes  (Read 2485 times)

0 Members and 1 Guest are viewing this topic.

Offline WebbotTopic starter

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,165
  • Helpful? 111
    • Webbot stuff
I2C woes
« on: December 12, 2012, 06:27:53 PM »
This is really a 'heads up' for people using 3v3 I2C sensors/devices with a 5v mcu (like the Axon I and Axon II).

Background: I2C normally works, in terms of sending 0s and 1s, by respectively driving the pin to 0V (for a 0) or making the pin 'open' and hence the pull-up resistors pull the line up to the supply voltage at the other end of the resistor.

For user simplicity many libraries, mine included, use the AVR internal pullup resistors (50k) to save you having to add extra resistors to your project. Since the Axons are 5v mcu then this means the 50k resistors pullup the line to 5V (since the current consumed by the attached sensor is minimal).

Assuming your I2C sensors use 5v then 'all is good'.

Next I added a BMP085 device from SparkFun https://www.sparkfun.com/products/11282 which operates at 3v3 and has its own 4k7 pullup resistors to 3v3.

Now the trouble starts........

In terms of powering the device then that's simple - just use the 3v3 power pins from the Axon II (in my case).
Low and behold everything works.
Then I thought - lets make sure my code doesn't crash if the device isn't there. Easy - just turn everything off, unplug the 3v3 supply to the sensor, and power on again - right ? Wrong - it blew up (silently!). What the! So it got me thinking....

With power applied the BMP085 was working at 3v3 but the I2C lines (SDA/SCL) had both the on board 4k7 pullups to 3v3 as well as the Axon 50k pullups to 5v - the result being not much above 3v3. What if i added a whole load of other I2C sensors that had their own pullups to 5v? The result would creep closer to 5v and eventually blow my 3v3 BMP085.

But what happened in my case? Well I guess that by removing the 3v3 supply to the BMP085 then its own pullups were now useless and the Axon pullups now set the I2C bus to 5v rather than 3v3 and so the BMP085 went bang. At least my $20 did !!

So here is what I surmise from this.....if all of your I2C sensors have the same Vcc as your processor then all is good - so long as something has a pullup - ie one or more sensors or your library does it on the mcu. The trouble begins when ANY of your I2C devices use supply voltages that are lower than your mcu.....

1. If the sensor boards have their own on-board pullups, and need different Vcc supplies, then you are stuffed!!! The actual voltage on the bus will be dictated by the combination of sensors: their on-board pullup resistors and their values. ie Adding 5v sensor number 10 could make 3v3 sensors 1,2, and 3 blow up.

2. Put different Vcc sensors on different I2C buses. eg for a 5V mcu like the Axon I or Axon II then you could use the hardware I2C with its internal pullups to drive 5V sensors.  If you have 3v3 sensors then use a bus with no pullups on the mcu and just use the pullups on the sensors - or if none then add your own pullups to the 3v3 supply.

3. A 3v3 mcu like the Axon Mote probably doesn't have the same problem - so long as its I2C sensors are 3v3 or higher.

You electro guys will no doubt come back to me ... but in the meantime I guess I have to 'blow' another $20 on a new BMP085 !




Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline jwatte

  • Supreme Robot
  • *****
  • Posts: 1,345
  • Helpful? 82
Re: I2C woes
« Reply #1 on: December 12, 2012, 06:57:26 PM »
That's pretty much how it works.

Note that the AVR is VERY forgiving to voltage sags on input. Anything above about 1V will count as "high."

Also, it's never considered a good idea to keep an IC (especially a CMOS IC) connected to input signals when power is off.

Finally, the current draw of an idle I2C input is not just low; it is effectively zero, because the inputs are CMOS, meaning that the gate capacitors charge, and then there is no current running, other than the very small leakage current of the CMOS input gates.

Offline WebbotTopic starter

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,165
  • Helpful? 111
    • Webbot stuff
Re: I2C woes
« Reply #2 on: December 12, 2012, 07:26:00 PM »
Yep - just stating a real life event.

"AVR is forgiving" - yep - but many sensors are not. Only need a few sensors to go and its more $ than the AVR. Again - just warning others "don't do as I did"

As I said in original post - its a 'heads up' - not a question. Hopefully may save others some $.

Edit:- Actually the more I think = the worse it gets! An I2C bus could have up to 127 devices/sensors connected. From what 'jwatte' says then if something snips the power line to the I2C devices but leaves the rest of the bus intact (ie one wire is cut) then it is 'normal' that my 127 devices/sensors go up in smoke - not just 'stop working' but they get 'fried forever'. Not aimed at jwatte!!! But it doesn't seem very 'mission critical'.
« Last Edit: December 12, 2012, 08:08:58 PM by Webbot »
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline Soeren

  • Supreme Robot
  • *****
  • Posts: 4,672
  • Helpful? 227
  • Mind Reading: 0.0
Re: I2C woes
« Reply #3 on: December 13, 2012, 05:56:23 PM »
Hi,

[...] An I2C bus could have up to 127 devices/sensors connected.
In case of many devices, both 3.3V and 5V, run two busses, one with a single bidirectional level converter inline and the problem goes away :)
Regards,
Søren

A rather fast and fairly heavy robot with quite large wheels needs what? A lot of power?
Please remember...
Engineering is based on numbers - not adjectives

Offline jwatte

  • Supreme Robot
  • *****
  • Posts: 1,345
  • Helpful? 82
Re: I2C woes
« Reply #4 on: December 13, 2012, 08:54:02 PM »
"AVR is forgiving" - yep - but many sensors are not. Only need a few sensors to go and its more $ than the AVR. Again - just warning others "don't do as I did"

My point is that you can always pull up your I2C bus to 3.3V rather than 5V. Add a second linear regulator if you need to. The AVR won't mind, and won't pull up the bus higher, because the bus is an open-drain sender-pulls-low design. And 3.3V is high enough for the AVR to count it as a "1."

The data sheet says you have to provide 0.6 * Vcc, or 3V in this case, for it to guarantee read as "high," and 0.3 * Vcc, or 1.5V or lower, to count as "0." -- My previous "over 1 V" number comes from operating at 3.3V on the internal resonator, and wasn't actually applicable to your case, but the method is still solid!

Offline Soeren

  • Supreme Robot
  • *****
  • Posts: 4,672
  • Helpful? 227
  • Mind Reading: 0.0
Re: I2C woes
« Reply #5 on: December 14, 2012, 10:59:24 AM »
Hi,

My point is that you can always pull up your I2C bus to 3.3V rather than 5V. Add a second linear regulator if you need to. The AVR won't mind, and won't pull up the bus higher, because the bus is an open-drain sender-pulls-low design. And 3.3V is high enough for the AVR to count it as a "1."
Just don't use too long leads then.
Open drain/collector outputs are used to lower the impedance of the signalling wire by using current signalling, but that takes the pull-up at the receiving end.
Placing the pull-up at the transmitting side reverts it to voltage signalling, which is far more susceptible to induced noise.
Regards,
Søren

A rather fast and fairly heavy robot with quite large wheels needs what? A lot of power?
Please remember...
Engineering is based on numbers - not adjectives

 


Get Your Ad Here