Hi,
What is the best way to read the state of an output pin? I have an LED connected to a pin and want to know in a different part of the program whether the LED is currently on or off.
Thanks,
Hi,
What is the best way to read the state of an output pin? I have an LED connected to a pin and want to know in a different part of the program whether the LED is currently on or off.
Thanks,
You can just check the same register that you wrote to. Are you using nrf_gpio_pin_write
? If you dig into how it works, you can find the OUT
, OUTSET
, and OUTCLR
registers. The OUTSET
and OUTCLR
registers simply modify the OUT
register, which holds the current output state.
In conclusion, NRF_GPIO->OUT
is the register you're looking for, and you just need to mask it to get the correct bit. The masking can also be found in nrf_gpio.h
, and will look something like this: ((NRF_GPIO->OUT >> pin_number) & 1UL)
.
You can just check the same register that you wrote to. Are you using nrf_gpio_pin_write
? If you dig into how it works, you can find the OUT
, OUTSET
, and OUTCLR
registers. The OUTSET
and OUTCLR
registers simply modify the OUT
register, which holds the current output state.
In conclusion, NRF_GPIO->OUT
is the register you're looking for, and you just need to mask it to get the correct bit. The masking can also be found in nrf_gpio.h
, and will look something like this: ((NRF_GPIO->OUT >> pin_number) & 1UL)
.
I think this is exactly what I was looking for, thanks. I will test it as soon as I can.
Isn't this what this function in nrf_gpio.h
is doing? uint32_t nrf_gpio_pin_out_read(uint32_t pin_number)
It appears so. However, this question was asked in reference to SDK 10. This function is only in SDK12 or later.