Hi. I have a problem with my NRF52840 Dongle. When using BSP driven button. I've tried to use some SDK precompiled examples - it doesn't work. Neither with ble_peripheral, nor ZigBee or Thread examples. Then I tried this code:
#include "boards.h"
int main(){
bsp_board_init(BSP_INIT_LEDS | BSP_INIT_BUTTONS);
while (true)
{
if (bsp_board_button_state_get(BSP_BUTTON_0)){
bsp_board_led_invert(BSP_BOARD_LED_2);
}
}
} and it worked as expected.
But the following code, which is intended to perform the same action:
#include "boards.h"
#include "app_timer.h"
#include "app_button.h"
static void buttons_handler(uint8_t pin, uint8_t action)
{
if (pin == BSP_BOARD_BUTTON_0){
if (action == APP_BUTTON_PUSH){
bsp_board_led_invert(BSP_BOARD_LED_0);
}
}
}
int main(void)
{
bsp_board_init(BSP_INIT_LEDS);
app_timer_init();
static app_button_cfg_t buttons [] = {
{BSP_BOARD_BUTTON_0, false, BUTTON_PULL, buttons_handler}
};
app_button_init(buttons, ARRAY_SIZE(buttons), APP_TIMER_TICKS(50));
app_button_enable();
} doesn't work.
This code works well:
#include <stdbool.h>
#include <stdint.h>
#include "boards.h"
#include "bsp.h"
#include "app_timer.h"
#include "nordic_common.h"
void bsp_evt_handler(bsp_event_t evt)
{
switch (evt)
{
case BSP_EVENT_KEY_0:
bsp_board_led_invert(BSP_BOARD_LED_0);
break;
default:
return;
}
}
int main(void){
NRF_CLOCK->LFCLKSRC = (CLOCK_LFCLKSRC_SRC_Xtal << CLOCK_LFCLKSRC_SRC_Pos);
NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
NRF_CLOCK->TASKS_LFCLKSTART = 1;
app_timer_init();
bsp_init(BSP_INIT_LEDS | BSP_INIT_BUTTONS, bsp_evt_handler);
while (true)
{
}
}
But the same construction in examples doesn't work (Ble blinky, for example).
I need some help because I don't know, where to look for some kind of solution.