in 8051, GPIO pins can be configed as both input and output buy putting pins in high-impedance state,then this pin can be read and write as input or output(like bus), in LPC21xx, a pin is either input or output, there is no high-impedance state, can I make one GPIO pin as input/output in LPC21xx?
thanks for your reply, I think my question is kind of confusing, I meant to ask what will happen if two output pins connected to one line, one is put the line to high, the other is put the line to low since LPC21xx GPIO pins have no tri-state.
in 8051 or other MCU, if two output pins are connected to one line, they can be configed as open-drain, then this line can be controlled by one output pin at a time, for example, if MCU want to release line, let other to set this line high or low, it put its output pin in tri- state, then this line can be put high or low by other.
That would be bad. Excessive current will flow from the 'high' pin to the 'low' pin, possibly causing damage the parts.
On the LPC21xx, you would have to switch the pin to an input. This will make it high-impedance, and it can be connected to an output pin without a problem.
If you just want to toggle between a strong low, and a weak high, you can connect a pull-up resistor to the pin and program a fixed '0' output value. Then you use the direction bit to switch between 0 (output) and weak 1 (input).
You can always accomplish this by writing a '0' to the pin, putting a pull-up on the pin and using the pin's direction bit to either (a) write a '0' (by setting the pin to output) or (b) writing a '1' / freeing the line (by setting the pin to input).
I have used this approach successfully, but there are 3 issues I can think of with it. First, pullups are slow, so your 0-to-1 transition won't be as fast as your 1-to-0 transition. I think the 8051 has a brief active pullup on a 0-to-1 transition to speed things up. Second, you'll have to check how fast the pin actually changes after you write to the direction bit and make sure your system can handle any delay there. Third, you may very well find that you need to write a '1' to put a '0' on the pin, and vice versa. If all of the drivers and receivers on the line can deal with it, you could use a pull-down rather than a pull-up and avoid the bit inversion issue (not that it's usually a big deal).
The trick for open drain is to set the ouput permanently to a '0', using IOCLR, and then use the IODIR direction register to set the output state. When it's an input, the pull-up resistor will pull the pin high. When it's an output, the preset 0 value takes it low.
Stephen Pelc, stephenXXX@mpeforth.com
MicroProcessor Engineering Ltd - More Real, Less Time
Um, when the pin is set to input it is tri-stated, it's not driving the output. It sounds more like you are looking for a Quasi bi- directional pin or possibly an open-collector.
As to what happens when two pins with different outputs are connected together, I doubt it's predictable. In the worst case it will be destructive if the drivers are beefy enough to overheat themselves.
I have used this approac many a time on various micros but found recently that it doesn't work for Sharp ARM LH754xx parts :-( What happens instead is that when the port is input the output register follows the input. So if you have a pull-up then switch from input to output will always drive high (unless somthing else was holding it low). Hopefully the LPC parts don't have this problem...