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

Parents
  • 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

Reply
  • 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

Children
No Data
Related