How to handle GPIO interrupts while it is configures to SENSE low

Hi all: All of the example code is using GPIOTE to demonstrate how to handle GPIO interrupt. However, it just can configured HiTOLow/LowToHi/Toggle. If I want to trigger the interrupt by sense Low/High, how can I implement the function. For example, we can register a event handler by calling the function of nrf_drv_gpiote_in_init(). How can I register a event handler to handle GPIO interrupts while it sense LOW/HIGH?


  • Hi, there are two example projects in the SDK that show usage of the gpiote module:


    Typically you initialize the gpiote module with nrf_drv_gpiote_init(), and then for each input pin you want to generate an interrupt you add nrf_drv_gpiote_in_init(), with a parameter to the event handler that should execute on pin change.

    You will notice that the gpiote driver is using the SENSE mechanism only, and not any of the IN events. Main reason for this is that the current consumption is much lower by using SENSE detect, and you are not limited to only 4 pins (there are only 4 configurable IN events).

    Typically the 4 OUT tasks and 4 IN events are used to control something directly through PPI without CPU interaction. For instance one of the examples show how a compare0 event from a timer can toggle an output pin directly.

  • I try to use external interrupt from pin.

    Use example \examples\peripheral\pin_change_int

    but doesn't work. I can't receive handler in_pin_handler()

    my code:

    void in_pin_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
    static void gpio_init2(void)
    ret_code_t err_code;
    err_code = nrf_drv_gpiote_init();
    //    nrf_drv_gpiote_out_config_t out_config = GPIOTE_CONFIG_OUT_SIMPLE(false);
    nrf_drv_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_LOTOHI(true);
    in_config.pull = NRF_GPIO_PIN_NOPULL;
    err_code = nrf_drv_gpiote_in_init(INT1, &in_config, in_pin_handler);
    nrf_drv_gpiote_in_event_enable(INT1, true);

    where is my wrong?