how to get real gpio high/low

Hi Nordic,

I am working with nRF52840, sdk17.1.0 and do the following test:

I use nrf_gpio_cfg_output(), nrf_gpio_pin_set(); to set gpio P1.00 to high and use nrf_gpio_pin_input_get() to read gpio level and the value is 1 (HIGH).

Next, I use a line to short P1.00 and ground and use rf_gpio_pin_input_get() to read gpio level and the value is "still" 1 (HIGH).    // I am supposed to get LOW

My questions are:

1. why can't get real high/low value?

2. I look into source code, does cod just return high/low form setting?

__STATIC_INLINE nrf_gpio_pin_input_t nrf_gpio_pin_input_get(uint32_t pin_number)
{
NRF_GPIO_Type * reg = nrf_gpio_pin_port_decode(&pin_number);

return (nrf_gpio_pin_input_t)((reg->PIN_CNF[pin_number] &
GPIO_PIN_CNF_INPUT_Msk) >> GPIO_PIN_CNF_INPUT_Pos);
}

3. Are there other functions to get real value?

best regards,

Gavin

  • Hello,

    If you have configured it as an output pin, so when you short it to GND, you just make a circuit from VDD to GND drawing current (if you put an LED in between it would light up). 

    If you want to use it to check for high or low, you need to configure it as an input pin instead of an output pin. nrf_gpio_cfg_input() instead of nrf_gpio_cfg_output();

    FYI: A common thing to do is to set up an event handler/button handler to trigger an interrupt when a button is pressed. You can look into one of the example using button handlers to see how you can do that, such as the SDK\examples\peripheral\bsp.

    Best regards,

    Edvin

  • Hi Edvin,

        Thanks for the response. One more question.
    There are two gpios. For example, one is P1.00, the other is P1.01.

    If I set P1.00 as output high and P1.01 as input/no pull.
    Then, short P1.00 and P1.01.

    Could I use nrf_gpio_pin_read() to read P1.01 high/low ? Is the answer high ?

    Best Regards,

    Gavin

  • Hello Gavin,

    panpgg said:

    Could I use nrf_gpio_pin_read() to read P1.01 high/low ? Is the answer high ?

    Did you try?

    It should be possible to do so.

    Best regards,

    Edvin

  • Hi Edvin,

    I have tested the experience and it is workable.

    sample code:

    nrf_gpio_cfg_output(NRF_GPIO_PIN_MAP(1, 0));
    nrf_gpio_pin_set(NRF_GPIO_PIN_MAP(1, 0));

    nrf_gpio_cfg_input(NRF_GPIO_PIN_MAP(1, 1), NRF_GPIO_PIN_PULLDOWN);

    // connect P1.00 and P1.01
    value = nrf_gpio_pin_read(NRF_GPIO_PIN_MAP(1, 1)); // high

    Thank you

    Best regards,

    Gavin

Related