Event handler of app_button isn't called

app_button_init()  and app_button_enable() returns NRF_SUCCESS. But event handler of app_button isn't called.

log messages of nRF52832 device is as follows.

00> <debug> app: app_button_init()       errCode=0x0
00> <debug> app: app_button_enable() errCode=0x0

Parents Reply Children
  • Hi,

    Not sure how the ble_app_blinky example reproduces your issue. Can you share your project so I could reproduce your results on my side? I can make the case private first if you prefer it?

    regards

    Jared

  • Hi 

    Jared is currently unavailable, and I will help you out in the mean time. 

    Thanks for sharing the code. 

    I see the code contains defines for running it on either a custom board or a DK. Do you see the same issue on the DK, or only on the custom board?

    Are you sure the button is connected the same way on the custom board as it is on the DK?
    The config enables pull up on the button input, which means the pin must be disconnected when the button is released, and pulled to ground when the button is pressed. 

    Have you tried to connect a scope or multimeter to the button input to verify that it has the expected voltage when the button is pressed and released?

    Best regards
    Torbjørn

  • I don't have DK. I use GPIOTE to detect button event. It can capture NRF_GPIOTE_POLARITY_TOGGLE event.

    The following is log messages of nRF52832 device.

    00><info> app: NRF_GPIOTE_POLARITY_TOGGLE

  • #include "app_button.h"
    #include "app_timer.h"
    #include "band_nctu.h"
    #include "button.h"
    #include "error.h"
    #include "nrf_drv_gpiote.h"
    #include "nrf_log.h"
    #include "timer.h"
    
    #define APP_BUTTON_UNKNOWN      2
    #define PIN_IN F1_BUTTON_1
    #define BUTTON_NUMBER           1
    #define BUTTON_DETECTION_DELAY  APP_TIMER_TICKS(50)    /**< Delay from a GPIOTE event until a button is reported as pushed (in number of timer ticks). */
    
    typedef enum {
        BUTTON_PRESS = 0,
        BUTTON_RELEASE
    } button_state_t;
    
    static bool _gButtonInitialized = false;
    static uint8_t _gButtonAction   = APP_BUTTON_UNKNOWN;
    
    void in_pin_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action) {
        switch (action) {
            case NRF_GPIOTE_POLARITY_LOTOHI:
            {
                NRF_LOG_DEBUG("NRF_GPIOTE_POLARITY_LOTOHI\n");
            }
            break;
                
            case NRF_GPIOTE_POLARITY_HITOLO:
            {
                NRF_LOG_DEBUG("NRF_GPIOTE_POLARITY_HITOLO\n");
            }
            break;
            
            case NRF_GPIOTE_POLARITY_TOGGLE:
            {
                NRF_LOG_INFO("NRF_GPIOTE_POLARITY_TOGGLE\n");
                const uint32_t buttonState = nrf_gpio_pin_read(F1_BUTTON_1);
                if (buttonState == BUTTON_PRESS) {
                    NRF_LOG_INFO("button pressed\n");
                    advertisingStart();
                    timerButtonLongPressStart();
                    _gButtonAction = BUTTON_PRESS;
                } else {
                    NRF_LOG_INFO("button released\n");
                    _gButtonAction = BUTTON_RELEASE;
                }
                
            }
            break;
        }        
    }
    
    int buttonInit(void) {
        ret_code_t errCode;
        nrf_drv_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_TOGGLE(true);
        in_config.pull = NRF_GPIO_PIN_PULLUP;
    
        errCode = nrf_drv_gpiote_in_init(PIN_IN, &in_config, in_pin_handler);
        if (errCode != NRF_SUCCESS) {
            NRF_LOG_WARNING("nrf_drv_gpiote_in_init() failed, errCode=0x%x\n", errCode);
            return ERROR_BUTTON_INITIALIZE_FAIL;
        }    
    
        nrf_drv_gpiote_in_event_enable(PIN_IN, true);
    
        const uint32_t buttonState = nrf_gpio_pin_read(F1_BUTTON_1);
        if (buttonState == BUTTON_PRESS) {
            timerButtonLongPressStart();
            _gButtonAction = APP_BUTTON_PUSH;
        }   
    
        _gButtonInitialized = true;
        return 0;
    }
    
    #if 0
    void button_events_init(void) {
        nrf_gpio_cfg_input(BUTTON_1,NRF_GPIO_PIN_PULLUP);
        
        timerButtonScanStart();    
    }
    #endif
    
    

Related