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

clear external interrupt

link text from this post i am generating interrupt using button 3. when i push my button,interrupt generates,LED turn on. but after turning on LED, i want to clear interrupt. so LED become off.here i don't want to use nrf_drv_gpiote_out_toggle(); function. my code is here

void gpiote_evt_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
{
    switch(action)
    {
       case NRF_GPIOTE_POLARITY_HITOLO:
			
			 nrf_drv_gpiote_out_clear(LED_3);	
            break;
        default:
            
            break;
    }
} 
Parents
  • You have to set the input pin to generate events on both High-to-Low and Low-to-High transitions(NRF_GPIOTE_POLARITY_TOGGLE). In the event handler you have to check if the pin is set( i.e. HIGH ) or not and based on that clear or set the LED.

    void gpiote_evt_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
    {
        switch(action)
        {
            case NRF_GPIOTE_POLARITY_TOGGLE:
                if(nrf_drv_gpiote_in_is_set(INTERRUPT_PIN))
                {
                    nrf_drv_gpiote_out_set(LED_3);
                }
                else
                {
                    nrf_drv_gpiote_out_clear(LED_3);
                }
                break;
            default:
                //do nothing
                break;
        }
    }
    

    MAIN:

    In main you have to configure the input pin to generate the NRF_GPIOTE_POLARITY_TOGGLEevent when the pin state is changed.

    int main(void)
    {
        
        ret_code_t ret_code;
        
        // Initialize the GPIOTE Peripheral 
        ret_code = nrf_drv_gpiote_init();
        APP_ERROR_CHECK(ret_code);
        
        // Configure LED_3 pin as output
        nrf_drv_gpiote_out_config_t led_config = GPIOTE_CONFIG_OUT_TASK_LOW;
        
        // Initialize LED_3 pin as output
        ret_code =  nrf_drv_gpiote_out_init(LED_3, &led_config);
        APP_ERROR_CHECK(ret_code);
        
        
        
        // Configuration for Interrupt Pin
        nrf_drv_gpiote_in_config_t config =
        {
            .sense = NRF_GPIOTE_POLARITY_TOGGLE, 
            .pull = NRF_GPIO_PIN_PULLUP , 
            .is_watcher = false,
            .hi_accuracy = false
        };
            
        // Initialize Interrupt Pin
        ret_code = nrf_drv_gpiote_in_init(INTERRUPT_PIN, &config, gpiote_evt_handler);
        APP_ERROR_CHECK(ret_code);
        
        // Enable Interrupts from interrupt pin
        nrf_drv_gpiote_in_event_enable(INTERRUPT_PIN,true);
        
        
        while (true)
        {
            // Do nothing.
        }
    }
    
  • ok. i have defined two external interrupt. can you tell me how to assign priority to interrupt??

Reply Children
No Data
Related