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

System ON Sleep mode

Hi all,

In our project we are using nrf52810, SDK 15.0.0 and ble_app_uart.c example.

We are using our custom board in which MCU is communicating with BLE through wired UART.

we tried to implement Sleep mode in BLE. 

when we send "sleep\n" string from MCU to BLE, BLE need to go System ON sleep mode.

BLE need to wake up after receiving data from data from MCU.

we are using power manage function for sleep mode( please refer attached code).

It has to be in power manage mode until an interrupt has to occur but here it is coming out of power manage function once it enters.

Please give solution regarding the same.

Thanks,

venu



void power_manage( void )
{
    ret_code_t err_code = sd_app_evt_wait();
    APP_ERROR_CHECK(err_code);
	
}

/**@brief Application main function.
 */
int main(void)
{
    bool erase_bonds;

    // Initialize.
    uart_init();
    log_init();
    timers_init();
    buttons_leds_init(&erase_bonds);
    power_management_init();
    ble_stack_init();
    gap_params_init();
    gatt_init();
    services_init();
    advertising_init();
    conn_params_init();

    // Start execution.
    printf("\r\nUART started.\r\n");
    NRF_LOG_INFO("Debug logging for UART over RTT started.");
    advertising_start();

    // Enter main loop.
    for (;;)
    {

				 // comparing received string from MCU and going into System ON sleep mode 
				 
					if(strncmp("sleep", (char *)&data_array[0], 5) == 0) 
					{
							power_manage();
							data_length = 0;
						  
					}
    }
}

Parents Reply Children
  • Hi.

    There are two sleep modes on nRF52810, System ON sleep mode and System OFF sleep mode. They are explained in the product specification v1.2 (section 5.3.2 and 5.3.3)

    In System ON sleep mode the CPU will wake up on any event. In System OFF sleep mode the CPU can only wake up on GPIO, high value or voltage input crossing a certain value.

    System On sleep mode is the most used one since all peripherals can be active. This sleep mode is entered with the function __WFE() which is short for Wait For Event. However you will often see this code in examples:

    __SEV();
    __WFE();
    __WFE();

    This is because if the event flag is set when __WFE() is called, the function will clear the event flag and return immediately, therefore not go to sleep. __SEV() (Set EVent flag) sets the event flag, so __SEV() followed by __WFE() will clear the event flag without going to sleep. Then we are sure that in the next __WFE() the CPU will go to sleep. The SoftDevice function sd_app_evt_wait() will do the same as these calls and put the CPU to System ON sleep mode.

    sd_app_evt_wait() or the SEV WFE calls are often done inside the main while loop. After this call we can add code to be executed when the CPU wakes up from an event. You can also run code inside interrupts connected to the event, as these will run when the specific event happens and the system wakes up.

    idle_state_handle() is just a function that calls system on sleep after all advertising is done.

    - Andreas

Related