Pull
up and Pull down:
Assume
the following function.
(Example
1)
int
io_var = 0;
void
sw_routine(){
io_var = io_read(0xDEADBEEF);
}
(Example
2)
int
io_var = 1;
void
sw_routine()
{
io_var
= io_read(0xDEADBEEF);
}
The
exact value of io_var is read from the address 0xDEADBEEF. But, before assigning
value to it, it can be initialized to 0 or 1 rather than leaving it with garbase
values.
The
same thing is done by Pull-up or Pull-down circuit in electronics to the pin
which is left open. Initializing the pin with logic HIGH (+5v, etc.) is called
pull up. Initializing with logic
LOW (0v) is called pull-down. This is just initialization when the pin is not
connected to any active module. When the active module is driving the pin, the
driven value is
reflected regardless of the initial value.
This
will apply for input as well as output pin. If you want the pin to reflect what
exactly you write or to read exactly the pin status, then Pull-up/Pull-down can
be safely selected.
Open-collector/Open-drain/Wired-OR/Wired-AND
These all are about safely sharing a single line between multiple devices with simple logic.
Wired-OR:
(A+B+C+D)'
When
all devices A,B,C,D are in logic LOW, the output will be HIGH. When any one of
device becomes logic HIGH, then
the output will become LOW. Don't you think that this is enough to have a single
interrupt line to just signal CPU of
interrupt from devices. Only thing is the interrupt signal will be active LOW.
This is the reason why INT' and RST' signals are active LOW.
Wired-AND
is just complement of Wired-OR: (A.B.C.D)'
If
any one of device input is logic LOW, the output will be logic HIGH.
Open-collector/Open-drain:
In
case of NPN transister, it is called Open-collector. In case of MOSFET, it is
called Open-drain. Open-collector/Open-drain means "Emitter is connected to the
ground. Base is driven as Input. Collector is open as output". It acts just as a
Switch to pull the output line to LOW, when the base is driven by input. If you
connect a pull-up at output and tie output of all devices, when all devices are
idle, the output is at logic HIGH. When any device drive the switch, it can
safely pull only the shared output line to LOW. The meaning of sharing is when
one connected device driver LOW and other drives HIGH, there should not be any
short circuite. This is guaranteed with open-collector/open-drain.
One
more advantage is that the line voltage is decided by the external pull up
circuite. So, it can be used to interface two components of different voltage
levels.
I2C
bus has two lins SDA and SCL, both are open-drain with exactly two pull-up
resistors. I2C protocol is built-over the open-drain. Since I2C master initially
starts the transaction by pulling the clock and data lines, all other devices
just listen/senses the lines and decodes what the I2C master tries to say. After
sensing the address given by the master, the corresponding slave transfers the
data. But, master as well as devices just creates the data and clock pulses by
pulling down the output line to LOW. For detailed, I2C bus details, please refer
the following: The output line can be read just by reading it as input
pin.
So,
if you want to connect the pin to a shared bus or to interface with different
voltage level, configure it as open-drain/open-collector.
Interfacing
different voltate levels:
Passing
water from 3.3 water level canel to 5 water level will not damage. But, it is
not enough. What effects will it create? A few exceptions are on some CMOS
devices and when interfacing 3.3V to a 5V device with a Schmitt-Trigger input.
Why?
But,
passing water from 5 water level to 3 water level will damage the field.