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

app_button does not work on my project

Hi there,

I am porting the the app_button from the ble_blinky project to my own project which uses BLE functionality too, and it is not firing the button_event_handler after pressed a button.

I am calling initialize() from my main.c to initialize the timer, leds and buttons

below my code:

#define NRF_LOG_MODULE_NAME Peripheral
#include "nrf_log.h"
#include "nrf_log_ctrl.h"
NRF_LOG_MODULE_REGISTER();

#include "peripheral.h" // header for the functions here
#include "boards.h"
#include "app_timer.h"
#include "app_button.h"

#define LEDBUTTON_BUTTON                BSP_BUTTON_0                            /**< Button that will trigger the notification event with the LED Button Service */
#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 void timers_init(void)
	{
		ret_code_t err_code = app_timer_init();
		APP_ERROR_CHECK(err_code);
	}
	static void leds_init(void)
	{
		bsp_board_init(BSP_INIT_LEDS);
	}
	static void button_event_handler(uint8_t pin_no, uint8_t button_action)
	{
		ret_code_t err_code;
		NRF_LOG_INFO("button_event_handler");
		switch (pin_no)
		{
		case LEDBUTTON_BUTTON:
			NRF_LOG_INFO("Button .");

			break;

		default:
			APP_ERROR_HANDLER(pin_no);
			break;
		}
	}
	static void buttons_init(void)
	{
		ret_code_t err_code;
		static app_button_cfg_t buttons[] =
		{
			{ LEDBUTTON_BUTTON, false, BUTTON_PULL, button_event_handler }
		};

		err_code = app_button_init(buttons,	ARRAY_SIZE(buttons),BUTTON_DETECTION_DELAY);	
		APP_ERROR_CHECK(err_code);
	}
	void initialize()
	{
		leds_init();
		timers_init();
		buttons_init();
		app_button_enable();
	}

SDK15.2

sdk_config:.

NRFX_CLOCK_ENABLED 1

NRFX_GPIOTE_ENABLED 1

APP_TIMER_ENABLED 1

BUTTON_ENABLED 1

I added nrf_drv_clock.c ,nrfx_clock.c, nrfx_gpiote.c, app_button.c, app_timer.c and their headers to my project with no luck

if someone can give me an advise, thanks in advance

Related