teensy RTC, how to get access on linktime during run time

Status
Not open for further replies.

larry_berlin

Well-known member
Hello forum,

I have read the explanations of Paul regarding teensy RTC on thread https://forum.pjrc.com/threads/47988-Teensy3Time-ino-updates-wrong-time?highlight=RTC and found this very usefull.
My question is, how can I get the time, witch will be stored (hack in ardiuno during build) in case teensy RTC has stale timestamp, during run time of my code?
Any ideas?

Background of the question is, I want to determine whether the RTC has been reset.

Thanks
 
Hello forum,

I have read the explanations of Paul regarding teensy RTC on thread https://forum.pjrc.com/threads/47988-Teensy3Time-ino-updates-wrong-time?highlight=RTC and found this very usefull.
My question is, how can I get the time, witch will be stored (hack in ardiuno during build) in case teensy RTC has stale timestamp, during run time of my code?
Any ideas?

Background of the question is, I want to determine whether the RTC has been reset.

Thanks

Had just to do it

Code:
    uint32_t t0=rtc_get();
    uint32_t t1=(uint32_t)&__rtc_localtime;
    if((t1-t0)>100) rtc_set(t1);
this piece of code updates the clock if the RTC clock is at least 100 sec behind compile time.

to see if RTC is set at all see L1111 of mk20dx128.c in cores/teens3
 
Had just to do it

Code:
    uint32_t t0=rtc_get();
    uint32_t t1=(uint32_t)&__rtc_localtime;
    if((t1-t0)>100) rtc_set(t1);
this piece of code updates the clock if the RTC clock is at least 100 sec behind compile time.

to see if RTC is set at all see L1111 of mk20dx128.c in cores/teens3

Thank you very much. I didn''t know where to look in the core files.
I had just to add globaly "extern void *__rtc_localtime;" to my sketch to avoid compiler error.

Unfortunatly my external circuit draws to much current to maintain RTC for 20 or 30 seconds (when changing battery).
Nevertheless something learned.
 
Status
Not open for further replies.
Back
Top