cancel
Showing results for 
Search instead for 
Did you mean: 

The HAL function to read the current output status of a GPIO

diverger
Senior
Posted on September 13, 2017 at 08:24

If I configure one GPIO pin to output. Is there a function in HAL to read back the current output status of it?

12 REPLIES 12
Lohi
Associate III

"it doesn't have any advantage over reading the ODR register."

Well, another two years... there are times when it's useful to know what was written to a pin, which might, indeed, be different than what is "visible" at the pin...this can be useful when you have something on a pin which can "return" a different state than what was written.

I used this on an IC to do confirmation of a function that was written, as part of self-test:

Write hi to external device

Wait xx μs for it to perform it's internal function

Read pin value - if it's now low, the device returns a "good" response

OTOH, you may want to know that you've set the pin high, even if it reads low, in a case where you might be driving something like a high-gain npn transistor, or a low Vgth FET with a pull-down resistor...edge cases, but...

Lohi
Associate III

embedded systems can sometimes be helped by knowing the true "schematic" of the I/O pins, to allow more intimate knowledge of the behaviour in "funny" applications, or for more effective self-test operations.

Just a thought, based on 46 years of embedded systems and IC development (about 2 billion ICs served ;) )

Yep, just so that a HAL may only provide the "streamlined" version, the 99.9% use cases, but it's nice to have something written that clarifies exactly what is, or is not, explicitly provided, since some of us old "bare metal" fools sometimes use abstruse methods  ; -).