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
  • FormerMember
    0 FormerMember

    My guess is that you did not configure the pin as an output before using it to toggle. You can do that by nrf_gpio_cfg_output(INDICATE_LED); Actually you can change the toggling driver implementation to suit you as follows so as to not read again:

    __STATIC_INLINE bool nrf_gpio_pin_toggle(uint32_t pin_number)
    {
        const uint32_t pin_bit   = 1UL << pin_number;
        const uint32_t pin_state = ((NRF_GPIO->OUT >> pin_number) & 1UL);
    
        if (pin_state == 0)
        {
            // Current state low, set high.
            NRF_GPIO->OUTSET = pin_bit;
            return true;
        }
        else
        {
            // Current state high, set low.
            NRF_GPIO->OUTCLR = pin_bit;
            return false;
        }
    }
    
  • FormerMember
    0 FormerMember in reply to FormerMember

    Then either any other peripheral is controlling the pin. Or the pin is toggling or made high somewhere else. Best of luck.

Reply Children
No Data
Related