Hardware Reference
In-Depth Information
version 2.0. The 2.0 version is a little dated now, having been first introduced in 1998. It runs at 3.4 mHz and is often
referred to as high-speed mode. High-speed mode is capable of transferring 3.4 Mbit/s so it's no slouch for simple
devices. Do keep in mind that the 3.4 Mbit/s includes protocol overhead too. I can't see a character LCD streaming
3 Mbit/s of data at any one time.
Physical Layout
So what makes up the I2C bus? The I2C bus is a serial protocol that consists of two physical wires that can operate in
both directions. These two lines are known as the serial data line (SDA) and the serial clock line (SCL). These two lines
normally operate at 3.3 V or 5 V. Although the I2C standards do permit other voltages, they are not widely seen.
The SDA is where the transmission of data to and from the slaves/master occurs.
The SCL's job is to set the timing on the bus. It's also used to set flow control for the data
on the SDA.
By default the SDA and SCL are pulled high via a pull-up resistor (recall that we also learned about a pull-up
resistor in Chapter 3).
Raspberry Pi Tolerance and High-Level Voltage Input
One big thing to keep in mind when selecting I2C devices for the Raspberry Pi is that the I2C bus is not tolerant of 5 V.
So what's that mean to you exactly? It means you are limited to what devices you can safely put on the I2C bus of the
Raspberry Pi without letting the magic smoke out. For this you're going to need to read your friendly data sheet. I love
data sheets and you should too: they have very useful information.
The data sheet for your I2C device will contain an all importation value called “Vih,” or high-level voltage input.
This key value tells you what the I2C slave device will attempt to pull the SDA up to when it needs to place the line
high. Most of the time the Vih is a range expressed as a percentage above and below the supply voltage of the I2C slave
device. Some devices have a wide range for the Vih and others don't. If your device has a voltage source of 5 V and the
Vih of 4 to 5.5 V it will never be able to pull the SDA high on the Raspberry Pi. In short it won't work and may damage
your Raspberry Pi. So please do read the data sheets and try and avoid letting the magic smoke out. Choose 3.3-V
devices to be safe or at least check the data sheet to ensure that the Vih can go down to 3.3 V.
Pull-Up Resisters and Open Drains
Another important part of the I2C bus is the need for pull-up resistors. On the SDA and SCL you need to have a
resistor to pull each line to a known high state. In the case of the Raspberry Pi, it has 1.8K ohm resistors already. Don't
try and add external pull-up resistors to any of your I2C projects. Why do you need to pull up the lines? The design
of the I2C bus is that of an open drain. Sounds fancy? It's a simple concept, really. Just think of your kitchen sink
drain. You can only place things down the drain. Normally things should not come out of the drain; if they do you
have issues. It's the same for the I2C bus; it's always pulled to a low state. The low state is a drain and cannot without
external assistance go to a high state. This is where the pull-up resistors come into play. They pull up the line to high
by default. Now when a slave device needs to access the line it can pull the line down. When it's done, the line will
return to high as the resistors are pulling the line up. In the case of the Raspberry Pi the I2C bus is pulled up to 3.3 V.
Now what happens when you use the bus? When a slave device wants to use the bus it will pull the SDA low;
once the SDA is pulled low the slave device will then pull the SCL low to indicate to other slave devices that the bus
is in use. Once the slave has finished transmitting or receiving data it will let the SDA go high to signal the end of
transmission. It will then let the SCL go high to indicate the bus is no longer in use.
 
Search WWH ::




Custom Search