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

nRF 52 DK nrf_gpio_pin_read() always returning a 0 ?

Hi all,

I'm having an issue using the nrf_gpio_pin_read() function from the nrf_gpio.h file. When I call it every time after calling nrf_gpio_pin_toggle() on the same pin I am still always getting a 0 on my return. Any ideas as to why this is happening? Included code snippet below of usage.

nrf_gpio_pin_toggle(INDICATE_LED);
if(nrf_gpio_pin_read(INDICATE_LED)==0)
{
    for (uint32_t i = 0; i < length_on; i++)
    {
	    app_uart_put(L1ON[i]);
    }						
}
else  // NEVER GETTING IN HERE
{     // SHOULD BE WHEN PIN IS HIGH THOUGH
    for (uint32_t i = 0; i < length_off; i++)
    {
	    app_uart_put(L1OFF[i]);
    }
}

For clarification I am never making it into the else statement even though I should every other time the pin is toggled.

Any help would be appreciated, Thanks in advance!

Parents
  • If you want to use the pin as an output AND an input, the normal nrf_gpio_cfg_output() function won't work for you because it sets the pin as an output and disables the input buffer, you can see that in nrf_gpio.h and read about connecting the input buffer in section 14.1 of the reference manual.

    You can either set the pin up manually or call nrf_gpio_cfg_output() and then re-enable the input buffer with

    NRF_GPIO->PIN_CNF[INDICATE_LED] |= (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos);
    
Reply
  • If you want to use the pin as an output AND an input, the normal nrf_gpio_cfg_output() function won't work for you because it sets the pin as an output and disables the input buffer, you can see that in nrf_gpio.h and read about connecting the input buffer in section 14.1 of the reference manual.

    You can either set the pin up manually or call nrf_gpio_cfg_output() and then re-enable the input buffer with

    NRF_GPIO->PIN_CNF[INDICATE_LED] |= (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos);
    
Children
No Data
Related