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

GPIO Digital Output Not Working

Why isn't this working?

static void gpio_init(void)
{
    ret_code_t err_code;

    //NB as #include "bsp_btn_ble.h" is already initiated within main.c we do not need to initiate GPIO here
    if (!nrfx_gpiote_is_init) {
        err_code = nrfx_gpiote_init();
        APP_ERROR_CHECK(err_code);
    }

    nrfx_gpiote_out_config_t out_config = GPIOTE_CONFIG_OUT_SIMPLE(true); //GPIOTE_CONFIG_OUT_TASK_TOGGLE(false);
    out_config.init_state   = NRF_GPIOTE_INITIAL_VALUE_HIGH;
    out_config.task_pin     = true;
    err_code = nrfx_gpiote_out_init(MPU_RESET_PIN, &out_config);
    APP_ERROR_CHECK(err_code);
    nrfx_gpiote_out_task_enable(MPU_RESET_PIN);

}

The MPU_RESET_PIN is set to : NRF_GPIO_PIN_MAP(0, 20)

I can not seem to be able to alter the state of the PIN. Whenever I read the PIN its always HIGH.

I have successfully managed to work with in inout on NRF_GPIO_PIN_MAP(0, 19) and I know pin 20 is available and not mapped elsewhere.

  • Hello,

    Are you using the nRF52840 DK?

    If so, look at the back of the DK. You can see that the pins P0.20-P0.23 are the DIO0-3 on the QSPI. This means that these pins are not connected to the output pins on the DK, but directly connected to the QSPI flash chip that is mounted on the DK. If you want to route e.g. pin P0.20 out, you need to cut SB 12 and short SB 22. The solder bridges on the DK is also listed here.

    So, either cut and short(solder) the solder bridges, or use another GPIO for your application. If you want a quick test of your FW, e.g. pin P0.13 is connected to the GPIO (and the LED1 on the DK). So if you set P0.13 to 0, the LED will turn on, and if you set P0.13 to 1, the LED will turn off. Please note that if you do this in an example where the leds are controlled by the appilcation, such as the BLE examples, this may not work. 

    Another pin that isn't connected to anything is e.g. P0.24.

    Best regards,

    Edvin

  • Hi Edvin

    No I'm not using the nrf52840 DK (although I have one), instead I'm using a Spark-fun nrf52840 mini-pro. This board has free GPIOs on 19 through to 23.

    I have Pin 19 connected to the HW Interrupt of an MPU, which is working. I shifted the pin assignment around to test using Pin 20 as the interrupt, which worked, so I know its free and available to use.

    Thanks

    Andrew

  • Hello Andrew,

    Ok, just wanted to check.

    Looking at your code, I am not quite sure where you got that code from.

    Look at the example SDK\examples\peripheral\pin_change_int

    static void gpio_init(void)
    {
        ret_code_t err_code;
    
        err_code = nrf_drv_gpiote_init();
        APP_ERROR_CHECK(err_code);
    
        nrf_drv_gpiote_out_config_t out_config = GPIOTE_CONFIG_OUT_SIMPLE(false);
    
        err_code = nrf_drv_gpiote_out_init(PIN_OUT, &out_config);
        APP_ERROR_CHECK(err_code);
        
        ...

    Then you can use nrf_drv_gpiote_out_toggle(), nrf_drv_gpiote_out_clear() and nrf_drv_gpiote_out_set() to set the state of the pin.

    Best regards,

    Edvin

  • Hi

    I was trying to move to NRFX, still don't understand why my input on 19 works but my output on 20 doesn't:

        nrfx_gpiote_out_config_t out_config = GPIOTE_CONFIG_OUT_SIMPLE(false);
        err_code = nrfx_gpiote_out_init(MPU_RESET_PIN, &out_config);
        APP_ERROR_CHECK(err_code);
    
        nrfx_gpiote_out_set(MPU_RESET_PIN);
        NRF_LOG_INFO("RESET PIN : %d", nrf_gpio_pin_read(MPU_RESET_PIN));
        NRF_LOG_FLUSH();
        nrf_delay_ms(50);
        nrfx_gpiote_out_clear(MPU_RESET_PIN);
        NRF_LOG_INFO("RESET PIN : %d", nrf_gpio_pin_read(MPU_RESET_PIN));
        NRF_LOG_FLUSH();

    I receive:

    <info> app: RESET PIN : 0
    <info> app: RESET PIN : 0

    Thanks

    Andrew

  • Try to run the same code on the DK, does it replicate there? If so, is it possible to send the project, so that I can have a look?

    Best regards,

    Edvin

Related