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

internal RTC example

I am using the nRF9160dk development board and I could not find a test or example for the internal RTC. could you provide a simple example of using the internal RTC.

  • Hi,

    You can take a look at this sample, it uses the RTC directly.

    But for most use-cases, you should use the kernel timer instead (the kernel timer uses the RTC). See this page

    Snippet:

    struct k_timer single_shot_timer;
    struct k_timer multi_shot_timer;
    
    static void my_expiry_function_1(struct k_timer *timer)
    {
    	ARG_UNUSED(timer);
    	printk("single_shot_timer expired\n");
    
    }
    
    static void my_expiry_function_2(struct k_timer *timer)
    {
    	ARG_UNUSED(timer);
    	printk("multi_shot_timer expired\n");
    
    }
    
    void main(void)
    {
    	printk("The kernel timer sample started\n"); // Doc: https://docs.zephyrproject.org/latest/reference/kernel/timing/timers.html
    
    	/* start one single shot timer that expires after 5000 ms */
    	/* start one multi shot timer that expires after 5000ms, and then every 5000 ms */
        k_timer_start(&single_shot_timer, K_MSEC(5000),             0);
    	k_timer_start(&multi_shot_timer,  K_MSEC(5000), K_MSEC(5000) );
    }
    
    K_TIMER_DEFINE(single_shot_timer, my_expiry_function_1, NULL);
    K_TIMER_DEFINE(multi_shot_timer,  my_expiry_function_2, NULL);

  • Sigrud

    yes I know how to use the timers. that is not what I want here. I will use the timers for other things in the application. I want a real time clock that knows it is March 17,202 and will know months, days, leap years etc. I loaded and ran the RTC example you pointed me to. it did nothing so I assume I did not do the following.

    Starting nrfx rtc sample!
    To run in non-secure mode, you need to add RTC0 to spm.c

    I did not understand what this meant. what do I need to add and where do I add it to spm.c. if this is a real RTC then this is what I need. I could not find the supporting documention (apis, etc.).

  • I want a real time clock that knows it is March 17,202 and will know months, days, leap years etc.

    The RTC is not a real time clock, its a real time counter. For this calendar use-case, please have a look at this and this post.

Related