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

using sd_app_evt_wait() to enters into sleep mode during a waiting certain amount time

Hi there,

I am a using a nRF52/SDK 13 to communicate to an external board which uses AT commands,  I would like to save some battery during the time I perform my AT command and Wait for a response from a UART interruption.

for example: using nrf_dela_ms(); which use CPU cycles to generate the delay

Sending_AT_Command1

nrf_delay_ms(2000);  //waiting for response during a UART RX interruption

Sending_AT_Command2

nrf_delay_ms(2000);  //waiting for response during a UART RX interruption

Sending_AT_Command3

nrf_delay_ms(2000);  //waiting for response during a UART RX interruption

Instead of use nrf_delay_ms, Could I use a combination of sd_app_evt_wait + timer (app_timer_create)?

as far I know after called sd_app_evt_wait() it will put the device in a low consumption state and will wake up after an interruption event (also it won't enter in sleep mode if there are pending interruptions in the queue)

void timerhandler(void *p_context)
{
	Global_timer_exit = 0;
}
void Timer_delay(uint8_t seconds, bool Timer_Exit)
{
	ret_code_t err_code;
	app_timer_stop(Timer);


	Global_timer_exit = Timer_Exit;		//global variable
	app_timer_start(Timer, APP_TIMER_TICKS(seconds * 1000), NULL);
	
	sd_app_evt_wait();  //enters in low consumption or sleep mode
		
	while (Global_timer_exit) // waiting for the timerhandler to exit when Timer_Exit =0
	{}
}

int main(void)
{
	....
	//Timer configuration
	uint32_t err_code;
	err_code = app_timer_create(&Timer, APP_TIMER_MODE_SINGLE_SHOT, &timerhandler);
	APP_ERROR_CHECK(err_code);
	
	//Sending At commands
	Sending_AT_Command1
	Timer_delay(5, 1);  //waiting for response during a UART RX interruption
	Sending_AT_Command2
	Timer_delay(5, 1);  //waiting for response during a UART RX interruption
	Sending_AT_Command3
	Timer_delay(5, 1);  //waiting for response during a UART RX interruption
	
	for(;;)
	{
		app_sched_execute();
		PowerManage();
	}
}

The timer above works, but my device is not entering in sleep mode, I am not sure if it is the proper way to do a friendly battery delay using a Timer

Related