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

  • #include "app_button.h"
    #include "app_timer.h"
    #include "band_nctu.h"
    #include "button.h"
    #include "error.h"
    #include "nrf_log.h"
    
    #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). */
    
    static bool _gButtonInitialized = false;
    static void _buttonEventHandler(uint8_t pinNo, uint8_t buttonAction);
    static const app_button_cfg_t _gAppButton[BUTTONS_NUMBER] = {
        {BUTTON_1, false, BUTTON_PULL, _buttonEventHandler},
    };
    
    static void _buttonEventHandler(uint8_t pinNo, uint8_t buttonAction) {
        switch (buttonAction) {
            case APP_BUTTON_PUSH:
            {
                NRF_LOG_DEBUG("APP_BUTTON_PUSH\n");
            }    
            break;
    
            case APP_BUTTON_RELEASE:
            {
                NRF_LOG_DEBUG("APP_BUTTON_RELEASE\n");
            }    
            break;
        }    
    }    
     
    
    int buttonInit(void) {
        ret_code_t errCode;
        errCode = app_button_init(_gAppButton,
                                   BUTTON_NUMBER,
                                   BUTTON_DETECTION_DELAY);
        NRF_LOG_DEBUG("app_button_init() errCode=0x%x\n", errCode);
        if (errCode != NRF_SUCCESS) {
            NRF_LOG_WARNING("app_button_init() failed, errCode=0x%x\n", errCode);
            return ERROR_BUTTON_INITIALIZE_FAIL;
        }
    
        errCode = app_button_enable();
        NRF_LOG_DEBUG("app_button_enable() errCode=0x%x\n", errCode);
        if (errCode != NRF_SUCCESS) {
            NRF_LOG_WARNING("app_button_enable() failed, errCode=0x%x\n", errCode);
            return ERROR_BUTTON_INITIALIZE_FAIL;
        }
    
        _gButtonInitialized = true;
        return 0;
    }
    
    #if 0
    void button_events_init(void) {
        nrf_gpio_cfg_input(BUTTON_1,NRF_GPIO_PIN_PULLUP);
        
        timerButtonScanStart();    
    }
    #endif
    
    
    #include "sdk_config.h"
    #include "gpioe.h"
    #include "error.h"
    #include "nrf_drv_gpiote.h"
    #include "nrf_log.h"
    
    static bool _gGpioteInitialized = false;
    int gpioeInit(void) {
        ret_code_t errCode;
        errCode = nrf_drv_gpiote_init();
        if (errCode != NRF_SUCCESS) {
            NRF_LOG_WARNING("nrf_drv_gpiote_init() failed, errCode=0x%x\n", errCode);
            return ERROR_GPIOE_INITIALIZE_FAIL;
        }
    
        _gGpioteInitialized = true;
    
        return 0;
    }
    
    
    

  • Hi,

    Are you using the Softdevice? If not, then take a look at my answer here. Slight smile

    regards

    Jared 

  • Hi.

    Can you share your project?

    regards

    Jared

  • I have shared button.c and gripe.c. And I call gpioe initialize and button initialize function in main(). Do you have suggested examples for app_button?

Related