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

Stop and restart APP_TIMER doesn't work with SDK12

I use an app_timer to periodically update sensor reading in my application. There is a characteristic used to change updating rate by stopping and restarting the app_timer:

app_timer_stop(m_our_char_timer_id);
app_timer_start(m_our_char_timer_id, APP_TIMER_TICKS(1000, APP_TIMER_PRESCALER), NULL); //1000ms
			

It works fine with SDK11. But with SDK12, I couldn't receive any data package after stopping and restarting the app_timer. Weird thing is, usually after 5 to 6 minutes, it resumes updating again.

Any help is appreciated. Thanks.

Parents
  • Here is the part changing interval using a characteristic

        // Update rate characteristic handler
    if(p_ble_evt->evt.gatts_evt.params.write.handle == p_our_service->char_handles_rate.value_handle)
    {
    	timer = true;
    	// Get data
    	sd_ble_gatts_value_get(p_our_service->conn_handle, p_our_service->char_handles_rate.value_handle, &rx_data);
    	switch(data_buffer){
    		case 0x10:// 10Hz
    		app_timer_stop(m_our_char_timer_id);
    		app_timer_start(m_our_char_timer_id, OUR_CHAR_TIMER_INTERVAL, NULL);
    		break;
    		case 0x02://2Hz
    		app_timer_stop(m_our_char_timer_id);
    		app_timer_start(m_our_char_timer_id, APP_TIMER_TICKS(500, APP_TIMER_PRESCALER), NULL); // 500ms
    		break;
    		case 0x05://5Hz
    		app_timer_stop(m_our_char_timer_id);
    		app_timer_start(m_our_char_timer_id, APP_TIMER_TICKS(200, APP_TIMER_PRESCALER), NULL); //200ms
    		break;
    		case 0x01://1Hz
    		app_timer_stop(m_our_char_timer_id);
    		app_timer_start(m_our_char_timer_id, APP_TIMER_TICKS(1000, APP_TIMER_PRESCALER), NULL); //1000ms
    		break;
    		default:
    		break;
    	}
     }
    
Reply
  • Here is the part changing interval using a characteristic

        // Update rate characteristic handler
    if(p_ble_evt->evt.gatts_evt.params.write.handle == p_our_service->char_handles_rate.value_handle)
    {
    	timer = true;
    	// Get data
    	sd_ble_gatts_value_get(p_our_service->conn_handle, p_our_service->char_handles_rate.value_handle, &rx_data);
    	switch(data_buffer){
    		case 0x10:// 10Hz
    		app_timer_stop(m_our_char_timer_id);
    		app_timer_start(m_our_char_timer_id, OUR_CHAR_TIMER_INTERVAL, NULL);
    		break;
    		case 0x02://2Hz
    		app_timer_stop(m_our_char_timer_id);
    		app_timer_start(m_our_char_timer_id, APP_TIMER_TICKS(500, APP_TIMER_PRESCALER), NULL); // 500ms
    		break;
    		case 0x05://5Hz
    		app_timer_stop(m_our_char_timer_id);
    		app_timer_start(m_our_char_timer_id, APP_TIMER_TICKS(200, APP_TIMER_PRESCALER), NULL); //200ms
    		break;
    		case 0x01://1Hz
    		app_timer_stop(m_our_char_timer_id);
    		app_timer_start(m_our_char_timer_id, APP_TIMER_TICKS(1000, APP_TIMER_PRESCALER), NULL); //1000ms
    		break;
    		default:
    		break;
    	}
     }
    
Children
No Data
Related