Example of sleep mode operation

We want to keep only the RTC active and the other peripherals in sleep mode, and wake up peripherals (e.g. communication by ESB) cyclically triggered by the RTC.

However, there are examples of system off (e.g. 'Power Management' ,  'Low Power Transmitter (with ESB) '  ),  but I cannot find any examples of sleep (system on and in low power mode).
Please provide any suitable program samples to understand the sleep operation.

  • Hi,

    The majority of examples use system ON sleep mode, which is precisely that the CPU is sleeping (using WFE either directly or via a library), and using the RTC to wake up. This mechanism is quite simple and not directly related to ESB, so you can use other examples and the same approach in your ESB application. One is simply the RTC example, which does exactly what I have described. Often it makes sense to use the app timer library to handle the RTC, as this will give you are more high level API and handle multiple timers baed on the RTC. Then, just enter sleep in the main loop.

  • Hi 

    Thanks for the replies.

    (1) By 'The majority of examples' do you mean 'Real Time Counter Example'?

    (2) In this example, there is a '__WFE()', is this not an assembler program module?
    I don't know assembler, so I want to write the same function as this '__WFE()' in C.

    (3) So I looked at the 'API Reference--SDK common libraries--Application Timer' in the Guide nRF5 SDK v17.1.0. However, 'drv_rtc_start', 'drv_rtc_stop', 'app_timer_start' and 'app_timer_stop' are available, but I cannot find any function corresponding to 'sleep'.
    Can you tell me how to write an equivalent function to '__WFE()', i.e. in C where the CPU goes to sleep and the RTC keeps ticking without completely stopping?

  • TML_YT said:
    (1) By 'The majority of examples' do you mean 'Real Time Counter Example'?

    By majority of examples I mean most examples, including the Real Time Counter Example.

    TML_YT said:
    (2) In this example, there is a '__WFE()', is this not an assembler program module?
    I don't know assembler, so I want to write the same function as this '__WFE()' in C.

    This is a C function, but it maps to a assembly instruction, yes. If you are using a SoftDevice, you should use sd_app_evt_wait() instead, and this calls __WFE internally. Alternatively, you can use the power management library which will call sd_app_evt_wait if using a SoftDevice or __WFE() if not (see implementation of nrf_pwr_mgmt_run() in components/libraries/pwr_mgmt/nrf_pwr_mgmt.c. If you compare, you will see that it does the same as the RTC example.

    TML_YT said:
    (3) So I looked at the 'API Reference--SDK common libraries--Application Timer' in the Guide nRF5 SDK v17.1.0. However, 'drv_rtc_start', 'drv_rtc_stop', 'app_timer_start' and 'app_timer_stop' are available, but I cannot find any function corresponding to 'sleep'.

    The RTC itself has nothing to do with sleep. But it can run while the CPU is sleeping and wake up the CPU with an interrupt (like most other peripheral, but others generally have a high current consumption so you want to disable those before sleeping the CPU). So in a nutshell, make the CPU sleep, but before that, configure the RTC (if you like) to wake up the CPU at a specific time. This used by virtually all real nRF applications.

    TML_YT said:
    Can you tell me how to write an equivalent function to '__WFE()', i.e. in C where the CPU goes to sleep and the RTC keeps ticking without completely stopping?

    The RTC never stops just because the CPU goes to sleep. It only stops if you either stop it explicitly, or stop the LF clock (32.768 kHz explicitly). Typically you always let these run. The example you are asking about here is really just the RTC example I pointed to before. Or you can look at this app timer tutorial, which shows much of the same but using the app timer library which is based on the RTC.

  • I have used the function 'nrf_pwr_mgmt_run' in 'Power management' to ensure low consumption and also that it starts with a timer interrupt.
    Indeed, the timer seems to be running continuously without stopping.

    On the other hand, the Low Power Transmitter/Receiver Example is an example of Enhanced ShockBurst. In it, the user-defined function 'system_off' is called. In this function, the following program is in effect running.
    -----------------------------------
    void system_off( void )
    {
    NRF_POWER->SYSTEMOFF = 0x1;
    (void) NRF_POWER->SYSTEMOFF;
    while (true);
    }
    -----------------------------------
    In this case, it appears to be waking up with a switch.

    (1) What is the difference between the earlier nrf_pwr_mgmt_run and NRF_POWER->SYSTEMOFF operation?
    NRF_POWER->SYSTEMOFF seems to consume less current.

    (2) NRF_POWER->SYSTEMOFF wake-up is performed by port (DETECT signal), can NRF_POWER->SYSTEMOFF wake-up be performed by a timer interrupt?

  • Hi,

    TML_YT said:
    (1) What is the difference between the earlier nrf_pwr_mgmt_run and NRF_POWER->SYSTEMOFF operation?
    NRF_POWER->SYSTEMOFF seems to consume less current.

    With the power management module, you basically get a WFE in the end (wait for event). This is what is also referred to as system ON low power mode, and is the normal low power mode, where for instance the 32.768 kHz clock and RTC can keep running. With system OFF low power mode on the other hand, there are no clocks running

    TML_YT said:
    (2) NRF_POWER->SYSTEMOFF wake-up is performed by port (DETECT signal), can NRF_POWER->SYSTEMOFF wake-up be performed by a timer interrupt?

    No.  The only way to wake up the nRF is with one of a few specific external wakeup signals (GPIO, LPCOMP, NFC or pin reset). A wakeup from system off is always in form of a reset.

Related