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

why the timer callback can't be called in a loop?

SDK14+NRF52832.

I used one timer to do something every millisecond. and I used another function to do a loop action, the function maybe breaked if the time period exceed one value.

now I found when execute the loop action function, the timer can't trigger, if normally it should be called every millisecond.

#define NRF_TICK_INTERVAL      APP_TIMER_TICKS(1)
static void nrf_tick_init(void)
{
	uint32_t err_code;
    
	err_code = app_timer_create(&m_nrf_tick_timer_id,  APP_TIMER_MODE_REPEATED,  nrf_tick_event_handler);
	APP_ERROR_CHECK(err_code);
	err_code = app_timer_start(m_nrf_tick_timer_id, NRF_TICK_INTERVAL, NULL);
	APP_ERROR_CHECK(err_code);
}

void nrf_ticks_set(unsigned long tick)
{
	nrf_ms_ticks = tick;
}

//-----------------------------------------------------------------
int nrf_ticks_get(unsigned long *tick)  
{
    *tick = nrf_ms_ticks;
    return 0;
}


//-----------------------------------------------------------------
static void nrf_tick_event_handler(void * p_context)
{

	UNUSED_PARAMETER(p_context);
	nrf_ms_ticks++;
	NRF_LOG_PRINTF("%s\n", __FUNCTION__);
}
void home_motor_then_stop(void)
{
	NRF_LOG_PRINTF("HOMEing...\n");
	bool tail_flag = Is_arrived_tail_point();
	unsigned long start_time = 0, end_time = 0, interval_len;
	
	if(false == tail_flag)
	{
		set_motor_to_tail(GLOBAL_MIN_GRADE); 
		nrf_ticks_get(&start_time);
		end_time = start_time;
		while((false==tail_flag)&&((end_time-start_time)<=30000)) //the end_time can't increase
		{
			nrf_ticks_get(&end_time); //always get the same value
			interval_len = end_time - start_time;
			NRF_LOG_PRINTF("stop_cup_then_home, interval_len=%d\n ", interval_len);
			tail_flag = Is_arrived_tail_point();
			
		};
		stop_motor();
	}
}

int main(void)
{

	application_init();//here called nrf_tick_init()
	
	home_motor_then_stop(); //
	
	while(1)
	{
		power_manage();
	}
} //

I found when run into the while of home_motor_then_stop(), the nrf_tick_event_handler can't trigger. this lead the function can't return.

what fault ?

Related