This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nrf_gpio_pin_read() return always 0 with a GPIO as output

Hi all,

i need to read the status on my GPIO where there is a led.

I have configured it like a:

     nrf_drv_gpiote_out_config_t configLed = GPIOTE_CONFIG_OUT_SIMPLE(true);
      nrf_drv_gpiote_out_init(LED_2, &configLed);
      nrf_drv_gpiote_out_init(LED_1, &configLed);
      nrf_drv_gpiote_out_init(LED_3, &configLed);

but if i try to read the value with nrf_gpio_pin_read() return always 0.

What does it means "

 * @brief Function for reading the input level of a GPIO pin.
  Note that the pin must have input connected for the value
  returned from this function to be valid."
Parents
  • It means you cannot use pin as input (read function), when it is configured as output. Why don't you just keep the state of the output as some variable?

Reply
  • It means you cannot use pin as input (read function), when it is configured as output. Why don't you just keep the state of the output as some variable?

Children
  • mmmh the idea is read a value of gpio to understand if the led is broken (for example) or others. I want use a characteristics on ble to do it. So i need to know the state of gpio

  • I am not very into hardware, but that does not have any sense for me. How would you check if led is broken, by setting the state of the output to high, and later checking if it is really high? If you set it high, pin is high. But that does not mean led is ok or not ok. Maybe you could try measuring ex. if the current is drawn there, or by some photoresistor...

  • The sense is this:

    If there is 100000 device in production, it can be useful understand if need change only a led or is a board nrf52 broken.

  • Ok i think i understand now - so you need some kind of self-diagnostic of the pin, so it can be verified if it really sets high/low when you tell it to, right? I have never seen feature like this in any microcontrollers. You can connect the pin you want to diagnose to other pin that is configured as input, and then read it.

  • Yes, for the seld-diagnostic. in the production can be happen that the micro-controller can broken or a short circuit can be happen... Mmmh if i read the port ??? Can resolve the problem?

       uint8_t port0= nrf_gpio_port_read(NRF_GPIO_PORT_SELECT_PORT0);
       uint8_t port1= nrf_gpio_port_read(NRF_GPIO_PORT_SELECT_PORT1);
       uint8_t port2= nrf_gpio_port_read(NRF_GPIO_PORT_SELECT_PORT2);
       uint8_t port3= nrf_gpio_port_read(NRF_GPIO_PORT_SELECT_PORT3);