Hi,
I'm using following code, but app_button event is not invoked. I have also enabled the app_timer, app_button and gpiote in the sdk_config.h file. I'm using nrf52832 and laird dev kit for the chip.
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include "nordic_common.h"
#include "nrf.h"
#include "app_button.h"
#include "app_timer.h"
#include "app_uart.h"
#include "nrf_gpio.h"
#include "nrf_drv_gpiote.h"
#include "app_error.h"
#include "nrf_delay.h"
#include "nrf_log.h"
#include "nrf_log_ctrl.h"
#include "nrf_log_default_backends.h"
#define LED1 17
void init_clock()
{
NRF_CLOCK->LFCLKSRC = (CLOCK_LFCLKSRC_SRC_Xtal << CLOCK_LFCLKSRC_SRC_Pos);
NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
NRF_CLOCK->TASKS_LFCLKSTART = 1;
while (NRF_CLOCK->EVENTS_LFCLKSTARTED == 0); // Wait for clock to start
}
static void log_init(void)
{
ret_code_t err_code = NRF_LOG_INIT(NULL);
APP_ERROR_CHECK(err_code);
NRF_LOG_DEFAULT_BACKENDS_INIT();
}
void btn_handler(uint8_t pin_no, uint8_t button_action)
{ if (button_action == APP_BUTTON_PUSH)
{ nrf_gpio_pin_set(LED1);
}
else if(button_action == APP_BUTTON_RELEASE)
{ nrf_gpio_pin_clear(LED1);
}
}
static app_button_cfg_t btn_config = {15, APP_BUTTON_ACTIVE_LOW, NRF_GPIO_PIN_PULLUP, btn_handler};
/**@brief Application main function.
*/
int main(void)
{
bool erase_bonds;
uint32_t err_code = NRF_SUCCESS;
//uart_init();
log_init();
init_clock();
/*****************Push Button implementation***********************/
// Initialize.
err_code = app_timer_init();
APP_ERROR_CHECK(err_code);
nrf_gpio_cfg_output(LED1);
err_code = app_button_init(&btn_config, 1, 50);
NRF_LOG_INFO("button error_code: %u", err_code);
APP_ERROR_CHECK(err_code);
app_button_enable();
/*******************************************************************/
for (;;)
{ nrf_delay_ms(100);
UNUSED_RETURN_VALUE(NRF_LOG_PROCESS());
NRF_LOG_INFO("oksdnv");
NRF_LOG_FLUSH();
}
}