What is the I2C Sensor Bus?

The I2C bus is a simple and flexible way to transfer digital data between two electronic devices which may be physically seperate or contained on the same printed circuit board (PCB). The main processor chip on the Quadrino board  communicates with the accellerometer, gyro, mag and baro sensors using this I2C bus. Thus I often call this bus the "sensor" bus since it's more obvious than the I2C name (Inter-Integrated Circuit bus). I2C is the bus of choice for many sensors between many vendors. 

The main advantages to an I2C as opposed to other methods of sensor connection is:

  1. Only needs 2 wires to connect up to 255 devices.
  2. Did you read that ^^^, only 2 wires can link many devices together!!!
  3. Can be used with the same PCB, or link external sensors as well.
  4. Simple protocol means it can be implemented with simple hardware on simple embedded micro processors.

Here is how the I2C bus works. The two wires are called CLOCK and DATA. These are purely signal wires and provide no appreciable level of power.  Each time a pulse occurs on the clock pin, the digital state (HI or LOW) of the DATA pin is taken. This would represent a single bit of the data transfer, a 1 or a 0. Data is transferred 8 bits at a time, so there will be 8 pulses on the clock line to transfer each byte. 

 So that is the digital side of things, then there is the actual electrical signaling of this bus. The CLOCK/DATA pin of the I2C bus uses what is called an open-collector signal. What this means is the master side of the conversation either pulls the signal to GROUND (0v) or it lets it go – where “letting it go” means electrically disconnecting itself from the wire altogether. If all chips/sensors have “let the bus go” then the bus is free to float around to any voltage. We use “pull-up” resistors to keep this floating from happening. If no one is pulling the bus to GROUND, then these pull-up resistors will pull the bus voltage up to 5 volts (or 3.3 whatever). These resistors are intentionally weak, when any device pulls the bus to GROUND they are still there trying to pull it high but do not have anywhere near the strength to do so. It’s like a tug of rope between a geek and a gym freak. Any time the gym freak decides to pull the rope he’ll do so easily, but when he isn’t looking the geek can pull the rope back.

 So a device can only pull the signal to GROUND, it cannot pull it to 5v. This is the secret to the multi-device nature of the i2c bus. Two or more devices pulling the bus at the same time means they are all pulling to ground which is electrically ok – the conversation will fail, and the software will catch that, but no short will happen. In our world there is only 1 master device making requests, so these conflicts never happen anyway but there is such a thing as multi-master i2c buses. Now If we did allow a device to pull the signal to 5v, and another device pulled to GROUND at the same time then we have a short from 5v to ground and smoke comes out; never should 5v go directly to ground. Going through the pullup resistor is ok because they are so weak.

 

To contrast with the signaling in your computer, they use a push-pull type signal bus. This means the transmitter both pulls the signal to ground for a 0 bit and pushes it HIGH for a 1bit. It does this because it results in the fastest bit change - it's all for speed. In our i2c bus our speed is limited to 400KH


This is what I2C bus communication looks like on an oscilloscope. (yellow is CLOCK, blue is DATA.) When the bus is let go you can see it slowly rises 

I2C Signals

in voltage (via the pullups), when a device pulls the bus low it’s almost immediate, like falling off a cliff. That’s because the device (the gym freak) can pull the bus low very fast, but when it let’s go the weak pullups take time to pull it back up. The bus can only operate at 400KHz (sometimes up to 1MHz) because the weak resistors can only pull the signal back to high over time. That rise time is determined by the weakness of the pullups and the capacitance on the bus. Each sensor or device adds parasitic capacitance to the bus signals which reduces our top speed by slowing the rise time. We'd like to have as little parasitic capacitance as possible, but it cannot be fully eliminated.

In contrast, our desktop computers main bus uses fast 1GHz push-pull transmitters a 1000x faster. So it is true that our i2c bus transmitters are half, the bottom half to be exact, of a normal transmitter. Missing the top half is why it’s called open-collector…if the collector closes it’s pulled to GROUND if it’s open it let’s go to HIGH.