- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes, it is possible to reconfigure any pin at any time. How are you driving the GPIO? I would do it this way:
// Drive the GPIO LOW.
gpio_configurePin(PORT, PIN, GPIO_OUTPUT_ENABLE, GPIO_OUTPUT_LOW);
// Input and output disable GPIO (when PORT != 0 and PIN !=0). The last parameter is a don't care when output is not enabled.
gpio_configurePin(PORT, PIN, GPIO_INPUT_DISABLE, GPIO_OUTPUT_LOW);
// When PORT == 0 and PIN == 0 use this instead.
gpio_configurePin(PORT, PIN, 0x100, GPIO_OUTPUT_LOW);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Arvind,
So, oddly, this works OK for port 1 pin 11, but not for port 0, pin 14. I tried substituting 0x100 for INPUT_DISABLE, but this did not work.
I realize that 0,14 is the tag’s LED, but I removed the LED entries from the BLE_PROFILE_GPIO_CFG structure, so I don’t think that should be interfering.
0,14 works OK if I drive it high / low.
Any thoughts?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
And are you trying to do this on the tag or on your own board?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
it is my own board, but the design is quite similar. That port connects to an LED in the same way as the tag.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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!