nrf_drv_gpiote_in_init and nrf_gpio_cfg_input weird Problem

Hello,

we have a remote control with 7 buttons.

Every button shall wakeup the device from deep sleep.

Beside i will have an interrupt on Button 6 and 7.

So the problem is, if i call gpio_init(),

the button 1-5 won't work with :

bool Switch1(void) { return (bool)nrf_gpio_pin_read(BUTTON_1); }   

( the wakeup is still working )

If i comment out  gpio_init() all buttons are function as expected, beside that i don't have an intterupt.

static void gpio_init(void)
{
    ret_code_t err_code;

    err_code = nrf_drv_gpiote_init();
    APP_ERROR_CHECK(err_code);

    nrf_drv_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_HITOLO(true);
    in_config.pull = NRF_GPIO_PIN_PULLUP;

    err_code = nrf_drv_gpiote_in_init(BUTTON_7, &in_config, in_pin_handler);
    APP_ERROR_CHECK(err_code);

    nrf_drv_gpiote_in_event_enable(BUTTON_7, true);


     err_code = nrf_drv_gpiote_in_init(BUTTON_6, &in_config, in_pin_handler);
    APP_ERROR_CHECK(err_code);

    nrf_drv_gpiote_in_event_enable(BUTTON_6, true);
}

void InitIo(void)
{

    nrf_gpio_cfg_output(POWER_PIN); //  Power

    nrf_gpio_cfg_output(LED_1);
    nrf_gpio_cfg_output(LED_2);
    nrf_gpio_cfg_output(LED_3);
    nrf_gpio_cfg_output(LED_4);
    nrf_gpio_cfg_output(LED_5);
    nrf_gpio_cfg_output(LED_6);
    nrf_gpio_cfg_output(LED_7);
    nrf_gpio_cfg_output(LED_8);
    nrf_gpio_cfg_output(LED_9);
    nrf_gpio_cfg_output(LED_10);

    nrf_gpio_cfg_input(BUTTON_1, NRF_GPIO_PIN_PULLUP);
    nrf_gpio_cfg_input(BUTTON_2, NRF_GPIO_PIN_PULLUP);
    nrf_gpio_cfg_input(BUTTON_3, NRF_GPIO_PIN_PULLUP);
    nrf_gpio_cfg_input(BUTTON_4, NRF_GPIO_PIN_PULLUP);
    nrf_gpio_cfg_input(BUTTON_5, NRF_GPIO_PIN_PULLUP);
    nrf_gpio_cfg_input(BUTTON_6, NRF_GPIO_PIN_PULLUP);
    nrf_gpio_cfg_input(BUTTON_7, NRF_GPIO_PIN_PULLUP);


    // gpio_init() ;


    nrf_gpio_cfg_sense_input(BUTTON_1, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW);
    nrf_gpio_cfg_sense_input(BUTTON_2, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW);
    nrf_gpio_cfg_sense_input(BUTTON_3, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW);
    nrf_gpio_cfg_sense_input(BUTTON_4, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW);
    nrf_gpio_cfg_sense_input(BUTTON_5, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW);
    nrf_gpio_cfg_sense_input(BUTTON_6, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW);
    nrf_gpio_cfg_sense_input(BUTTON_7, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW);
}

  • Hi,

    I am not able to explain what you are seeing. Also, I attempted to reproduce by taking your code and doing some small changes. The complete main.c file I tested on a nRF52 DK looks like this:

    #include <stdio.h>
    #include <stdint.h>
    #include "nrf_delay.h"
    #include "app_error.h"
    #include "nrf_assert.h"
    #include "nrf_drv_gpiote.h"
    #include "nrf_gpiote.h"
    #include "nrf_gpio.h"
    
    #include "nrf_log.h"
    #include "nrf_log_ctrl.h"
    #include "nrf_log_default_backends.h"
    
    
    #define BUTTON_1 13
    #define BUTTON_2 14
    #define BUTTON_3 15
    #define BUTTON_4 16
    #define BUTTON_5 3
    #define BUTTON_6 4
    #define BUTTON_7 28
    
    
    static void in_pin_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
    {
        NRF_LOG_INFO("Pin %u action: %u", pin, action);
    }
    
    
    static void gpio_init(void)
    {
        ret_code_t err_code;
    
        err_code = nrf_drv_gpiote_init();
        APP_ERROR_CHECK(err_code);
    
        nrf_drv_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_HITOLO(true);
        in_config.pull = NRF_GPIO_PIN_PULLUP;
    
        err_code = nrf_drv_gpiote_in_init(BUTTON_7, &in_config, in_pin_handler);
        APP_ERROR_CHECK(err_code);
    
        nrf_drv_gpiote_in_event_enable(BUTTON_7, true);
    
    
         err_code = nrf_drv_gpiote_in_init(BUTTON_6, &in_config, in_pin_handler);
        APP_ERROR_CHECK(err_code);
    
        nrf_drv_gpiote_in_event_enable(BUTTON_6, true);
    }
    
    void InitIo(void)
    {
        nrf_gpio_cfg_input(BUTTON_1, NRF_GPIO_PIN_PULLUP);
        nrf_gpio_cfg_input(BUTTON_2, NRF_GPIO_PIN_PULLUP);
        nrf_gpio_cfg_input(BUTTON_3, NRF_GPIO_PIN_PULLUP);
        nrf_gpio_cfg_input(BUTTON_4, NRF_GPIO_PIN_PULLUP);
        nrf_gpio_cfg_input(BUTTON_5, NRF_GPIO_PIN_PULLUP);
        nrf_gpio_cfg_input(BUTTON_6, NRF_GPIO_PIN_PULLUP);
        nrf_gpio_cfg_input(BUTTON_7, NRF_GPIO_PIN_PULLUP);
    
    
        // gpio_init() ;
        nrf_gpio_cfg_sense_input(BUTTON_1, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW);
        nrf_gpio_cfg_sense_input(BUTTON_2, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW);
        nrf_gpio_cfg_sense_input(BUTTON_3, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW);
        nrf_gpio_cfg_sense_input(BUTTON_4, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW);
        nrf_gpio_cfg_sense_input(BUTTON_5, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW);
        nrf_gpio_cfg_sense_input(BUTTON_6, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW);
        nrf_gpio_cfg_sense_input(BUTTON_7, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW);
    }
    
    /** @brief Function for main application entry.
     */
    int main(void)
    {
        uint32_t err_code;
    
        err_code = NRF_LOG_INIT(NULL);
        APP_ERROR_CHECK(err_code);
    
        NRF_LOG_DEFAULT_BACKENDS_INIT();
    
        NRF_LOG_INFO("Started.");
    
        InitIo();
        gpio_init();
    
        while (true)
        {
             NRF_LOG_INFO("Sleeping...");
             __SEV();
             __WFE();
             __WFE();
             NRF_LOG_INFO("Awake!");
        }
    }
    

    Here I get an interrupt for BUTTON_6 and BUTTON_6, but the device wakes up on all "buttons".

    How do you verify that your device doe snot wake up? If you are not able to resolve it, can you make your code run on a DK (preferably as a minimal failing example), so that I can test on my end?

Related