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

Set a button as an interrupt source

Hi, I'm trying to set a button as an interrupt source. I wrote this code:

void Init(void){
	pwrmng_MainStatus = PWRMNG_STS_STARTUP;
	//LED
	#ifdef DEBUG_LED
	nrf_gpio_cfg_output(LED_R);
	nrf_gpio_cfg_output(LED_G);
	LED_G_TURN_OFF();
	LED_R_TURN_OFF();
	#endif

	//Interfaccia
	nrf_gpio_cfg_input(INTERFACE, NRF_GPIO_PIN_NOPULL);

	//Startup Moduli
	timers_init();
	ble_stack_init();
	gap_params_init();
	conn_params_init();
	
	//Bottone
	//button_init();
	IRQ_init();
}
uint32_t IRQ_init(void)
{
    uint32_t err_code = NRF_SUCCESS;
    nrf_drv_gpiote_in_config_t config_pin = GPIOTE_CONFIG_IN_SENSE_HITOLO(false);
    
    if (!nrf_drv_gpiote_is_init())
    {
        err_code = nrf_drv_gpiote_init();
        if (err_code != NRF_SUCCESS)
        {
            return err_code;
        }
    }    

    config_pin.pull = NRF_GPIO_PIN_NOPULL;

    err_code = nrf_drv_gpiote_in_init(BUTTON_0, &config_pin, button_evt_handler);
    if (err_code != NRF_SUCCESS)
    {
        return err_code;
    }    
    nrf_drv_gpiote_in_event_enable(BUTTON_0, true);    
    return(err_code);    
}

void button_evt_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
{
	pwrmng_MainStatus = PWRMNG_STS_SHUTDOWN;	
}

int main(void){	
	Init(); 
	for(;;){/* CODE */}
}

err_code is 0x00 so I think that the initialization of BUTTON_0 succeeded. The problem is that I never enter button_evt_handler() pushing the button. BUTTON_0 is PIN21 in my application and I can see PIN21 changing state going to DEBUGGING->PERIPHERALS->GPIO. What's wrong with my code? I'm using softdevice S130 and nRF51822. Thanks!

Parents Reply Children
No Data
Related