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.
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);
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);