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

app_timer_start delayed after disconnect

In my application I have a custom board with a single LED. While advertising the LED blinks at 1Hz and when connected the LED goes solid. However while testing with a proven Android application I notice that occasionally on disconnect the timer doesn't restart as desired but is instead delayed anywhere between 2 and 8 seconds. After that it begins blinking correctly. One thing to note is that I'm using the Internal RC which is temperature calibrated every 4 seconds. The following code will clarify the situation:

EDIT: I'm using SD 7.0.0 and SDK 6.0

Here you can see how I toggle the LED when connected/disconnected and call advertising_start when necessary.

case BLE_GAP_EVT_CONNECTED:
	m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
					
	// Stop the advertising LED timer
	err_code = app_timer_stop(m_app_timer_id);
	APP_ERROR_CHECK(err_code);
					
	// Make LED go solid indicating a connection
        nrf_gpio_pin_set(ADVERTISING_LED_PIN_NO);

        break;
            
case BLE_GAP_EVT_DISCONNECTED:
        m_conn_handle = BLE_CONN_HANDLE_INVALID;
				
	nrf_gpio_pin_clear(ADVERTISING_LED_PIN_NO);
        advertising_start();

        break;

In advertising start I kick off the timer as shown below (it's already created).

static void advertising_start(void)
{
    uint32_t             err_code;
    ble_gap_adv_params_t adv_params;
    
    // Start advertising
    memset(&adv_params, 0, sizeof(adv_params));
    
    adv_params.type        = BLE_GAP_ADV_TYPE_ADV_IND;
    adv_params.p_peer_addr = NULL;
    adv_params.fp          = BLE_GAP_ADV_FP_ANY;
    adv_params.interval    = APP_ADV_INTERVAL;
    adv_params.timeout     = APP_ADV_TIMEOUT_IN_SECONDS;

    err_code = sd_ble_gap_adv_start(&adv_params);
    APP_ERROR_CHECK(err_code);

	err_code = app_timer_start(m_app_timer_id, 32768/2, NULL);
	APP_ERROR_CHECK(err_code);
}
Parents Reply Children
No Data
Related