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

How to use of RTC to wake up from sleep

Hello,

I am after an example for nRF5340 showing how to use RTC to wake up from sleep.

I have a couple of timers running few tasks at regular intervals in a forever loop then I send the chip to sleep. At this point everything stops including the timers.

I need an interrupt source to wake the chip up and the RTC seems like a good way but I am not sure how to set it up and configure it to use.

Note, I am using SES V5.34a as a development environment and Zephyr V1.5.0-rc1.

Thank you.

Kind regards

Mohamed

Parents Reply Children
  • Thank you Einar for the quick response.

    I am not using threads for now. I may be using threads at some point in the near future.

    You are free to use an RTC peripheral directly and do it that way,

    Could you please provide an example where the RTC is used to come out of sleep?

    but there are few good reasons for not using the build in thread and work queues support in Zephyr as suggested above.

    Are you saying there are few good reasons for NOT using the built-in thread and work queues?

    In other ways you are discouraging me from using threads. Is this what you meant to say?

    Kind regards

    Mohamed

  • Hi Mohamed,

    Learner said:
    I am not using threads for now. I may be using threads at some point in the near future.

    If you are using Zephyr you are using threads, even if you may not be aware of it. Your main function is a thread (see system threads documentation for more). So using k_sleep is still the most appropriate.

    Learner said:
    Could you please provide an example where the RTC is used to come out of sleep?

    There are no official simple RTC sample in the NCS, but you can refer to this unofficial sample (it is for the nRF9160 but the code is equally relevant for the nRF53).

    Learner said:
    Are you saying there are few good reasons for NOT using the built-in thread and work queues?

    Yes.

    Learner said:
    In other ways you are discouraging me from using threads. Is this what you meant to say?

    No, I am discouraging you from using the RTC driver and handling this yourself as the appropriate way to do this is to use what Zephyr provides for you. To expand on this: Using an RTC directly will work, and it is not complicated. But it is just not clean to use a special approach in place of a core feature of the RTOS you are using which does exactly the same thing.

    Einar

  • Thank you.

    I get it that my main() function is an implicit thread running under Zephyr.

    I tried to get to the source code of the basic thread example but I could not. All I could see was the README.html file.

    How can I view and download the project?

    Kind regards

    Mohamed

  • Hi Mohamed,

    The sample is located under <ncs>/zephyr/samples/basic/threads/

    Einar

  • Thank you Einar.

    I got it.

    You are right I do not need to use RTC, k_sleep() will do the job.

    I am trying to optimise power usage, will k_sleep() put peripheral devices such as ADC, SPI in low power mode?

    Or do I have to do this separately before calling k_sleep()? 

    Kind regards

    Mohamed

Related