how to set high priority to push button

I'm using nrf51822. I have a program which shut down the system when the button is clicked. however, not every time I click the button, the system respond. my system is full of other events (interrupts). the BUTTON_DETECTION_DELAY is set to 1 second. I want a long press before going down.

void buttons_init(void)
    static app_button_cfg_t buttons[] = {
        {ON_OFF_BUTTON_PIN_NO, false, NRF_GPIO_PIN_PULLUP, button_event_handler},

    uint32_t err_code = app_button_init(buttons, sizeof(buttons) / sizeof(buttons[0]), BUTTON_DETECTION_DELAY);

    err_code = app_button_enable();

void button_event_handler(uint8_t pin_no, uint8_t button_action)
      // set turn off flag, and turn off from main loop

how can I set the button handler the rightest priority

  • Hi

    The button handler should have APP_IRQ_PRIORITY_HIGH priority by default. This is set in the app_gpiote_init function. app_button uses app_gpiote library.

    This link could also help with understanding the debouncing functionality further.

    It looks like you use pullup for your button, which means it is not floating, so that is not the reason for your problem.

    If it still does not work, you could try the example on this thread, to see if it works better.

    If you are using softdevice and a lot of other interrupts, a possible explanation is that the button signal is toggled to fast and an interrupt is missed, see this thread.

  • For this to work, you need to define Button_detection_delay right?

    Can I know the function which you  have written for defininng this detection of delay