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
  • OK, thank you.

    Your answer has led me to my next question.

    How do I disable or power down the peripherals e.g. ADC, SPI...?

    Kind regards

    Mohamed

  • Hi Mohamed,

    That is different for different peripherals and also sometimes depending on which driver you use. Often it is enough to not have an active transaction or stopping it (so essentially not use it). In some other cases you may need to uninit the driver in order to properly shut down. You can refer to the API of the relevant drivers to see how.

    Also, it may be useful to experiment by commenting out initialization and usage of peripherals and gradually include again if you have a unexpected current consumption and want to narrow down where what causes it. Then you can look at that peripheral and the related code specifically.

    Einar

  • Thank you Einar.

    I experimented with the ADC and stopped reading the ADC results to see what effect it has on current consumption. To my disbelief the current consumption increased. How can this be?

    Note, the ADC was still initialised and bound. For the ADC peripheral there must be a disable or power down procedure to go through.

    I have not played with the SPI yet.

    Kind regards

    Mohamed

  • Hi Mohamed,

    Are you using the nrfx_saadc API? If so you can call nrfx_saadc_uninit() after finishing the conversion. If current consumption is still high after uninitializing then you can use the following as well:

        *(volatile uint32_t *)0x40007FFC = 0;
        *(volatile uint32_t *)0x40007FFC = 1;

    The above snippet uses an undocumented register to reset the SAADC peripheral.

    Einar

  • Hi Einar,

    Thank you for the tips.

    Are you using the nrfx_saadc API?

    I am not sure. How do I know for sure if I am using nrfx_saadc API?

    I looked in the build.emProject file and I can see the following which suggests I am using nrfx_saadc API. An extract from build.emProject is included below. The file nrfx_saadc_uninit() is declared in the header file C:\Zypher\v1.5.0-rc1\modules\hal\nordic\nrfx\drivers\include\nrfx_saadc.h which is included in the project file below. However, I cannot build the project because it returns the error undefined reference to nrfx_saadc_uninit().

    </project>
    <project Name="app/libapp.a">
    <configuration
    Name="Common"
    build_output_file_name="app\libapp.a"
    project_dependencies="cmake_object_order_depends_target_app;cmake_object_order_depends_target_app;cmake_object_order_depends_target_app;cmake_object_order_depends_target_app;cmake_object_order_depends_target_app;cmake_object_order_depends_target_app;cmake_object_order_depends_target_app;cmake_object_order_depends_target_app;cmake_object_order_depends_target_app;cmake_object_order_depends_target_app;cmake_object_order_depends_target_app;cmake_object_order_depends_target_app;cmake_object_order_depends_target_app;zephyr/driver_validation_h_target;zephyr/kobj_types_h_target;zephyr/syscall_list_h_target;zephyr/zephyr_generated_headers"
    project_directory=""
    project_type="Externally Built Library" />
    <folder Name="C_COMPILER__app_">
    <file file_name="../src/adc/pid4_adc.c">
    <configuration
    Name="Common"
    build_dependency_file_name="$(ProjectDir)/CMakeFiles\app.dir\src\adc\pid4_adc.c.obj.d"
    build_object_file_name="CMakeFiles/app.dir/src/adc/pid4_adc.c.obj"
    c_only_additional_options="-DBUILD_VERSION=v2.4.99-ncs1-rc1;-DKERNEL;-DNRF5340_XXAA_APPLICATION;-DUSE_PARTITION_MANAGER=0;-D_FORTIFY_SOURCE=2;-D__LINUX_ERRNO_EXTENSIONS__;-D__PROGRAM_START;-D__ZEPHYR__=1;
    -IC:/Zypher/v1.5.0-rc1/modules/hal/nordic/nrfx/drivers/include
    -IC:/Zypher/v1.5.0-rc1/zephyr/include;-Izephyr/include/generated;
    -IC:/Zypher/v1.5.0-rc1/zephyr/soc/arm/nordic_nrf/nrf53;
    -IC:/Zypher/v1.5.0-rc1/zephyr/lib/libc/newlib/include;
    -IC:/Zypher/v1.5.0-rc1/nrf/include;
    -IC:/Zypher/v1.5.0-rc1/modules/hal/cmsis/CMSIS/Core/Include;
    -IC:/Zypher/v1.5.0-rc1/modules/hal/nordic/nrfx;
    -IC:/Zypher/v1.5.0-rc1/modules/hal/nordic/nrfx/drivers/include;
    -IC:/Zypher/v1.5.0-rc1/modules/hal/nordic/nrfx/mdk;
    -IC:/Zypher/v1.5.0-rc1/zephyr/modules/hal_nordic/nrfx/.;
    -IC:/Zypher/v1.5.0-rc1/modules/debug/segger/rtt;
    -isystem;C:/Zypher/v1.5.0-rc1/nrfxlib/crypto/nrf_cc312_platform/include;
    -Og;-imacros;
    ...

    I have this config line in my prj.conf file 

    CONFIG_ADC=y

    Which header file should I be including?

    Kind regards

    Mohamed

Related