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

SDK 16.0 APP_BUTTON_RELEASE event not received when waking up from a button press

I just updated my project from SDK 15.3 to 16.0. I am using the nRF52840.

I am not receiving the APP_BUTTON_RELEASE event when waking up from a button press. It used to work on 15.3.

To help isolate the problem, I recreated it in the ble_app_template example project and ran it in both SDK 15.3 and 16.0 on the Nordic dev board. I made the following changes in each SDK:

In bsp.c, in the bsp_button_event_handler() , I added the following serial debug line of code:

Fullscreen
1
2
3
case APP_BUTTON_RELEASE:
(void)app_timer_stop(m_bsp_button_tmr);
NRF_LOG_RAW_INFO("button release\r\n");
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

In main.c, I modified the sleep_mode_enter() with a serial debug line of code and removed the APP_ERROR_CHECK() to simulate sleep while debugging:

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
static void sleep_mode_enter(void)
{
ret_code_t err_code;
NRF_LOG_RAW_INFO("sleep_mode_enter\r\n");
NRF_LOG_FLUSH();
err_code = bsp_indication_set(BSP_INDICATE_IDLE);
APP_ERROR_CHECK(err_code);
// Prepare wakeup buttons.
err_code = bsp_btn_ble_sleep_mode_prepare();
APP_ERROR_CHECK(err_code);
// Go to system-off mode (this function will not return; wakeup will cause a reset).
err_code = sd_power_system_off();
// APP_ERROR_CHECK(err_code);
while (1){}
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

In main.c, I also decreased advertising time to 10 seconds for convenience so that it will go to sleep sooner:

Fullscreen
1
#define APP_ADV_DURATION 1000
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

I run the app by:

  1. Start the ble_app_template example.
  2. Allow advertising to time out so that it goes into sleep mode.
  3. Press the button to wake it back up.

When I run the ble_app_template example in 15.3, I get the following Debug Terminal Output:

Fullscreen
1
2
3
4
5
6
7
<info> app: Template example started.
<info> app: Fast advertising.
sleep_mode_enter
<info> app: Template example started.
<info> app: Fast advertising.
button release
sleep_mode_enter
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

The app resets upon button press as expected. Notice "button release". This means that I get the button release event.

When I run the ble_app_template example in 16.0, I get the following Debug Terminal Output:

Fullscreen
1
2
3
4
5
6
7
8
<info> app_timer: RTC: initialized.
<info> app: Template example started.
<info> app: Fast advertising.
sleep_mode_enter
<info> app_timer: RTC: initialized.
<info> app: Template example started.
<info> app: Fast advertising.
sleep_mode_enter
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

The app resets upon button press as expected. Although, I do not get a button release event.

It is very important to my project to get this event. I need to detect the release event so that I can differentiate between a short and long press upon wakeup from a button press.