Is it possible to config GPIO pins in LPC21XX ARM to be in/out?

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 jet

Reply to
Loading thread data ...

Standard "classic" 8051 has quasi-bidirectional ports.

The LPC21xx ports can be configured as input or output.

From the LPC2138 Data sheets

6.10 General purpose parallel I/O

Device pins that are not connected to a specific peripheral function are controlled by the

GPIO registers. Pins may be dynamically configured as inputs or outputs. Separate

registers allow setting or clearing any number of outputs simultaneously. The value of the

output register may be read back, as well as the current state of the port pins.

6.10.1 Features

. Direction control of individual bits.

. Separate control of output set and clear.

. All I/O default to inputs after reset.

There is a reasonable Yahoo forum on the LPC2000 devices.

Reply to
Joe G (Home)

hi, Joe,

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.

--------------------- |

---------------------- | | | | | | |----------| | | | MCU | | | Other | | | |-------------| | | | | | | | | | | | --------------------- |

---------------------- | line(or bus)

after read LPC21xx datasheet, i wonder if LPC accomplish this by change pin direction to input, it didn't state how to put pin in tri- stae.

Reply to

sorry for the figure.

--------------------- | ---------------------- | | | | | | |----------| | | | MCU | | | Other | | | |-------------| | | | | | | | | | | | --------------------- | ---------------------- | l> hi, Joe,

Reply to

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).

Reply to

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).

Reply to
Mike Silva

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,
MicroProcessor Engineering Ltd - More Real, Less Time
 Click to see the full signature
Reply to
Stephen Pelc

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.


Reply to
Robert Adsett

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...


Reply to
Peter Dickerson

And I forgot to mention that if you don't need IIC these chips already have outputs that do that.


Reply to
Robert Adsett

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.