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

Question about set GPIO pin status

Hi,

I have a question about setting the gpio pin status. From the picture, it seems that the value on the right represents the status of the gpio pin. So the default value is 2, which means using input mode and disconnecting with input buffer, right? Can we set the status by writing the value with "nrf_gpio_pin_write".  For example, "nrf_gpio_pin_write(17,1)" and "gpio_pin_cfg_output(17)", are those two sentences have the same function?

Actually, I have tried to use "nrf_gpio_pin_write", but it never works. I have configured the corresponding pin as output, but I still cannot write value to that pin. Could you please tell me what is the possible reason for this? 

Thanks in advance for your help.

Parents Reply
  • #define LNA_ENABLE_PIN 17  //P0.17

    nrf_gpio_cfg_output(LNA_ENABLE_PIN);
    nrf_gpio_pin_set(LNA_ENABLE_PIN);

    also yours nrf_gpio_pin_write(17, 1); is okay

    output low:nrf_gpio_pin_clear(LNA_ENABLE_PIN); or nrf_gpio_pin_write(17, 0); 

    Your question 1. You try the code configuration P0.17 but fail.

    I think the most reasons are assigned the configuration by the other application. You may check your sdk_config.h

    Maybe you can find P0.17 for other functions as input.

Children
  • Thanks very much for your fast response. The picture shows all my main function in my project. I do not configure this pin anywhere else, even in the sdk_config.h. But when I checking the register, the output is not clear after "nrf_gpio_pin_clear(19)", and you can see I cannot even set the breakpoint to check the "nrf_gpio_pin_write" (no arrow mark on the left). Do I miss something in order to change the status of the gpio pin?

  • The code is okay. And the debug message told you it's output. However, I think your debug break-point is wrong. Because the main loop should for(;;) or while(1) loop. Even through you trace the function. You should make the break-point with some command.

    For example:

    void system_io_init(void)
    {
    nrf_gpio_cfg_output(LNA_ENABLE_PIN);
    nrf_gpio_pin_set(LNA_ENABLE_PIN);
    //nrf_gpio_pin_clear(LNA_ENABLE_PIN);
    }

    int main()

    {

      system_io_init();

    ble_stack_init();

    db_discovery_init();
    gatt_c_init();

    // Start scanning for peripherals and initiate connection to devices which
    // advertise.
    scan_start();

    for (;;)
    {
    if (NRF_LOG_PROCESS() == false)
    {
    // Wait for BLE events.

    nrf_gpio_pin_set(LNA_ENABLE_PIN);
    power_manage();

    nrf_gpio_pin_clear(LNA_ENABLE_PIN);
    }
    else
    {
    nrf_gpio_pin_clear(LNA_ENABLE_PIN);

    my_delay(50);//    Break-point here
    }
    }

    }

Related