Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 4 of 4

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

  1. #1
    Senior Member
    Join Date
    May 2017
    Posts
    106

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

    Hello forum,

    I have read the explanations of Paul regarding teensy RTC on thread https://forum.pjrc.com/threads/47988...?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

  2. #2
    Senior Member
    Join Date
    Jul 2014
    Posts
    3,063
    Quote Originally Posted by larry_berlin View Post
    Hello forum,

    I have read the explanations of Paul regarding teensy RTC on thread https://forum.pjrc.com/threads/47988...?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

  3. #3
    Senior Member
    Join Date
    May 2017
    Posts
    106
    Quote Originally Posted by WMXZ View Post
    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.

  4. #4
    Senior Member
    Join Date
    Jul 2014
    Posts
    3,063
    Quote Originally Posted by larry_berlin View Post
    I had just to add globaly "extern void *__rtc_localtime;" to my sketch to avoid compiler error.
    that's correct, sorry for reduced cut/paste

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •