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

long press button to start advertisement does not work

Hello,

I am trying to make a beacon start advertising on a long press of a button. Using this as a reference, I implemented a timer as follows:

this is the flag to keep track of advertising status-

Fullscreen
1
static bool advflag = false;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

this is the handler and timer creation/start-

Note that, I am using m_timer_id which is a repeated timer for some other purpose. The timer used for the button is m_timer_b which is a single shot timer.

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
static void timer_b_handler(void * p_context)
{
uint32_t err_code;
if(nrf_gpio_pin_read(BSP_BUTTON_0)==0){
err_code = ble_advertising_start(BLE_ADV_MODE_FAST);
APP_ERROR_CHECK(err_code);
nrf_gpio_pin_toggle(BSP_LED_2);
}
}
// Create timers
static void create_timers()
{
uint32_t err_code;
// Create timers
err_code = app_timer_create(&m_timer_id,
APP_TIMER_MODE_REPEATED,
timer_a_handler);
APP_ERROR_CHECK(err_code);
err_code = app_timer_create(&m_timer_id_b,
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

I even made changes in the softdevice event handler-

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
static void on_ble_evt(ble_evt_t * p_ble_evt)
{
uint32_t err_code;
switch (p_ble_evt->header.evt_id)
{
case BLE_GAP_EVT_CONNECTED:
err_code = bsp_indication_set(BSP_INDICATE_CONNECTED);
APP_ERROR_CHECK(err_code);
m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
advflag=true;
scan_start();
break;
case BLE_GAP_EVT_DISCONNECTED:
err_code = bsp_indication_set(BSP_INDICATE_IDLE);
APP_ERROR_CHECK(err_code);
m_conn_handle = BLE_CONN_HANDLE_INVALID;
advflag=false;
scan_start();
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

What I have observed is that, when i press and hold the button, both LED! and LED3 flash once and the board does not do anything

(I'm assuming the device reset?.If so, i dont understand why, i assumed using the flag fixes the advertising while already advertising problem ).

But when i hold the button even after those 2 LEDs have flashed, the device works as required while i keep the button pressed.

I am using the nRF52832 development board, nRF5 SDK11.0 and keil uvision5

Any solutions to this would be appreciated.

Thank you.