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

How do I use button Push Interrupt

I want to change Variable state( 0->1 or 1->0) when I push the button.

I was searching for example relating to the GPIO.

but I did not find that i want.

Everything is a timer example

I would like to implement a function that operates when just press a button(using a interrupt).

You can do the advice would be appreciated.

I'd like to get help on how to implement.

What should I do?

I use nrf51822-DK and small button.

Parents
  • You can use the GPIOTE module (nRF51 Series Reference Manual section 14). Here is a small example that will toggle a LED when you push a button:

    #include "nrf_gpiote.h"
    #include "boards.h"
    
    #define GPIOTE_CHANNEL_0 0
    
    // Interrupt handler
    void GPIOTE_IRQHandler(){
    	  nrf_gpio_pin_toggle(BSP_LED_0);
    	  NRF_GPIOTE->EVENTS_IN[0] = 0;
    }
    
    int main(void)
    {
        nrf_gpio_cfg_output(BSP_LED_0);  //Configure LED 0 as output
    	nrf_gpio_cfg_input(BSP_BUTTON_0,BUTTON_PULL); //Configure button 0 as input
        //Configure GPIOTE channel 0, to generate an event from button 0:
    	nrf_gpiote_event_config(GPIOTE_CHANNEL_0, BSP_BUTTON_0, NRF_GPIOTE_POLARITY_HITOLO); 
    	NRF_GPIOTE->INTENSET = GPIOTE_INTENSET_IN0_Enabled; //Set GPIOTE interrupt register on channel 0
    	NVIC_EnableIRQ(GPIOTE_IRQn); //Enable interrupts
        for(;;){}
    }
    
  • samet, function was renamed to nrf_gpiote_event_configure.

Reply Children
No Data
Related