Is it possible to switch a GPIO from input to output after it is configured?

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
legic_1490776
Level 5
Level 5
25 likes received 10 likes received First like received

I am using a GPIO pin to control an LED, active low.

It occurred to me that it might be possible to set the GPIO to high impedance (input and output disabled) when the LED is not in use.

However, it seems like only the first call to gpio_configurePin() has an effect.  Is there any way to change the configuration of a pin after configuring it once?

0 Likes
1 Solution

OK, I got it to work, but it’s a little strange. I found that the port 0 pins behave strangely (I have 3 port 0 pins that I want to drive this way).

For any port 0 pin, I found that I need to FIRST initialize it to output high. After setting it output high, I’m able to switch it back and forth to hi-z and output low. Note, my code is also using 0x100 instead of INPUT_DISABLE.

For the port 1 pin, it works without the first step.

My original code initialized it by setting it high-Z directly, but this apparently gets it into a state where it won’t subsequently drive low.

Thanks for the tips!

View solution in original post

0 Likes
5 Replies