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

Interrupt on falling edge

Hello community

In the pin_change_int example the following code is written:

    err_code = nrf_drv_gpiote_in_init(PIN_IN, &in_config, in_pin_handler);

So, this basically means: whenever PIN_IN goes from low to high, the 'in_pin_handler' is called.

Is there a quick and easy way to make it call the 'in_pin_handler' when PIN_IN goes from high to low (instead of low to high)? 

Thanks!

  • Hi,

    The second parameter to nrf_drv_gpiote_in_init() is of type nrf_drv_gpiote_in_config_t, and this configures the the interrupt generation. You should configure it with one of three macros:

    • GPIOTE_CONFIG_IN_SENSE_HITOLO to get an interrupt when the input goes from high to low (falling edge)
    • GPIOTE_CONFIG_IN_SENSE_LOTOHI to get an interrupt when the input goes from low to high (rising edge)
    • GPIOTE_CONFIG_IN_SENSE_TOGGLE to get interrupts on both edges.

    So in practice, you just need to change your code to something similar to this:

        nrf_drv_gpiote_in_config_t config = GPIOTE_CONFIG_IN_SENSE_HITOLO(true);
        err_code = nrf_drv_gpiote_in_init(p_btn->pin_no, &config, gpiote_event_handler);
        VERIFY_SUCCESS(err_code);

Related