When reading a manual on using a PICAXE and an I2C device I saw this diagram.
I can't work how this would behave as wouldn't it make the connection on the lines constantly high due to the connection to the power rail, so never goes low. I understand that they are open-drain lines and they are needed inorder to make the lines go high but how can it make them go low with that connection to the positive rail?
-
2\$\begingroup\$ electronics.stackexchange.com/questions/7423/… \$\endgroup\$– Toby JaffeyFeb 1, 2011 at 0:07
3 Answers
The resistors you see are called "pull up" resistors; they literally "pull up" the signal to the positive voltage rail.
I2C is a communication bus that allows multiple devices to talk on it. Since there is only a clock and data line there is no way to ensure that two devices won't start talking at the same time, or a device mis-identifies a message as being for it and responds out of turn.
If two devices try to control the data line and one wants it '1' and the other '0' you end up with a condition called contention. Internally a normal digital output is built up out of two transistors: one connects the signal line to +V and the other to ground. The device turns on one transistor or the other to set the output signal to the appropriate level. When two devices are trying to make the same signal two different voltages you end up with +V connected to ground through two transistors. This is known as contention and is something you want to avoid because it causes high currents and can damage one or both of the output drivers.
In order to get around this problem, the I2C specification requires the use of "open collector" or "open drain" (same thing) drivers. This means that the devices on the bus can ONLY connect the signal to ground. The only way for a device to output a '1' is to not drive the line to zero. Something has to bring the line to a logic '1' and that something is the pull-up resistor.
What happens now if two devices try to drive the data line is that one is not doing anything (it wants the line to be '1') and the other device has its output transistor turned on, connecting the signal to ground. The resulting signal is a '0' -- there is no contention because the only thing holding trying to make the line a '1' is a resistor which by design limits the amount of current it allows through. Pull-up resistors are usually selected to offer a bit of resistance to a changing signal but not too much. For I2C the value for a pull up is usually 4700-10000 ohms.
Check out http://en.wikipedia.org/wiki/Open_collector and http://en.wikipedia.org/wiki/I%C2%B2C for more information.
-
\$\begingroup\$ I like how you've answered the question above and beyond what Dean is looking for (with your explanation on I2C). \$\endgroup\$ Feb 2, 2011 at 0:40
Those are pull-up resistors. When devices aren't communicating the resistors pull both lines to high. A device is able to pull the lines low. It has to supply current that gets dissipated by the pull up resistors. You can think of this like a basic V=IR problem to determine how much current is required.
The reasoning for this setup is the situation where you want to have multiple devices communicating on a single line. If you had a device pulling the line high instead of the pull up resistors, when a different device tries to communicate it will be forced to overcome the other device in order to pull the line low. In this situation you still have a V=IR problem, except this time your R is very very small which makes I very very large.
-
1\$\begingroup\$ Maybe i'm reading this wrong but "A device is able to pull the lines low. It has to supply current that gets dissipated by the pull up resistors. " I think you mean 'It' ( the device ) has to sink whatever current is required to pull the output pin to ~0V rather than supply it. \$\endgroup\$– MarkJan 31, 2011 at 23:41
-
\$\begingroup\$ Its all sorta relative. Sure it is sinking current, but I could also argue that it is supplying negative current. \$\endgroup\$– KellenjbJan 31, 2011 at 23:43
They are required by the I2C specification.
They can be driven low by making the output pin low.