Hi my goal is to put the NRF into system on low power mode every other second. I have a repeated app_timer that increments counter variable m_custom_value every second. I thought of two possible ways to do this by calling sd_app_evt_wait() if/while m_custom_value % 2 == 0.
1. I was wondering if there is any difference if I use an if statement vs while loop to call sd_app_evt_wait(). If I use an if statement then sd_app_evt_wait() is only called once every other second, but if I use a while loop then sd_app_evt_wait() is called continuously for the duration of one second (or approximately one second), every other second. Will using a while loop just interrupt the NRF CPU from sleep or is there no difference between calling sd_app_evt_wait() once or calling sd_app_evt_wait() continuously for the duration where I want the NRF CPU to be sleeping?
2. Do I need to make sure the NRF is done advertising or force the NRF to stop advertising before calling sd_app_evt_wait() if I want the NRF CPU to go to system on low power mode?
I noticed that if I start BLE advertising then call sd_app_evt_wait() the NRF DK will continue advertising until the advertising timeout or idle power-management code is called. So my current assumption is that if BLE advertising is still active when sd_app_evt_wait() is called, then the NRF CPU will not go to sleep and the active BLE advertising will continue draining significant power.
#define NOTIFICATION_INTERVAL APP_TIMER_TICKS(1000) APP_TIMER_DEF(m_busy_wait_timer_id); static uint8_t m_custom_value = 0; static void notification_timeout_handler(void * p_context) { UNUSED_PARAMETER(p_context); ret_code_t err_code; // Increment the value of m_custom_value before notifying it. m_custom_value++; } static void timers_init(void) { // Initialize timer module. ret_code_t err_code = app_timer_init(); APP_ERROR_CHECK(err_code); app_timer_create(&m_notification_timer_id, APP_TIMER_MODE_REPEATED, notification_timeout_handler); } static void application_timers_start(void) { app_timer_start(m_notification_timer_id, NOTIFICATION_INTERVAL, NULL); } int main(void) { bool erase_bonds; // Initialize. log_init(); timers_init(); application_timers_start(); buttons_leds_init(&erase_bonds); power_management_init(); ble_stack_init(); gap_params_init(); gatt_init(); peer_manager_init(); services_init(); advertising_init(); conn_params_init(); NRF_LOG_INFO("Template example started."); advertising_start(erase_bonds); // Enter main loop. for (;;) { while(m_custom_value % 2 == 0){ sd_app_evt_wait(); } // vs? if(m_custom_value % 2 == 0){ sd_app_evt_wait(); } } }