From 2cb4d4aa1a88caac291a7de9c3d0fa65a18caab0 Mon Sep 17 00:00:00 2001 From: Graham Sanderson Date: Tue, 17 May 2022 13:11:57 -0500 Subject: [PATCH] Add delay to hello_rtc (#109) (#215) A delay is needed after `rtc_set_datetime()` before the newly set value can be read back. Co-authored-by: Rene Greiner --- rtc/hello_rtc/hello_rtc.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/rtc/hello_rtc/hello_rtc.c b/rtc/hello_rtc/hello_rtc.c index 59cd6fa..b59cea0 100644 --- a/rtc/hello_rtc/hello_rtc.c +++ b/rtc/hello_rtc/hello_rtc.c @@ -32,6 +32,10 @@ int main() { rtc_init(); rtc_set_datetime(&t); + // clk_sys is >2000x faster than clk_rtc, so datetime is not updated immediately when rtc_get_datetime() is called. + // tbe delay is up to 3 RTC clock cycles (which is 64us with the default clock settings) + sleep_us(64); + // Print the time while (true) { rtc_get_datetime(&t);