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
  • In this case, the issue was resolved through MyPage. It was found that starting an app_timer instance in interrupt context (ie: on_ble_evt() function) caused a delay of 1 to 10 seconds before the timer instance started.

    The workaround was to schedule the app_timer_start() call to main-context (using a scheduler or a flag) instead of calling it from interrupt context. This behavior is reported back to Nordic's SDK team.

    Cheers, Håkon

  • I looked at this post: devzone.nordicsemi.com/.../

    To figure out how to use the scheduler. However I'm not completely sure how to actually start the timer with the scheduler.

    I'm starting an ADC-timer in an interrupt context (now trying to move that to the scheduler). What I'm doing is:

    app_shed_event_put(m_adc_sampling_timer_id, sizeof(m_adc_sampling_timer_id) ,app_timer_start).

    This is not working and I'm not expecting it to since I'm giving it the wrong types.

    My question is:

    Do I need to make a function that starts the timer for me, and then call the function from the app_shed_event_put ?

Reply
  • I looked at this post: devzone.nordicsemi.com/.../

    To figure out how to use the scheduler. However I'm not completely sure how to actually start the timer with the scheduler.

    I'm starting an ADC-timer in an interrupt context (now trying to move that to the scheduler). What I'm doing is:

    app_shed_event_put(m_adc_sampling_timer_id, sizeof(m_adc_sampling_timer_id) ,app_timer_start).

    This is not working and I'm not expecting it to since I'm giving it the wrong types.

    My question is:

    Do I need to make a function that starts the timer for me, and then call the function from the app_shed_event_put ?

Children
No Data
Related