Forum Rule: Always post complete source code & details to reproduce any issue!
Page 2 of 2 FirstFirst 1 2
Results 26 to 30 of 30

Thread: How to access the internal RTC in a Teensy 4.0?

  1. #26
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    14,140
    Quote Originally Posted by PerM View Post
    I had trouble compiling my code (in the Arduino environment) when I had placed the definition of getTeensy3Time() in a separate file. After some head scratching, I realized I had to explicitly #include "core_pins.h" for the compiler to recognize the Teensy3Clock object. This was not necessary when I instead put the definition in the .ino file.

    So this is the relevant code in the separate cpp file:

    ...
    Maybe this can help someone else solve a similar issue.
    Only the .INO gets any default provided inclusions - primarily ARDUINO.h

    Adding just that should work and is less obscure.

  2. #27
    Junior Member
    Join Date
    May 2021
    Location
    Sweden
    Posts
    11
    Thanks defragster for that piece of information. Good to know.
    I am more used to an ordinary C/C++ environment where there is perhaps more to learn to get started, but also less of the "helpful" Arduino magic that can let one down in unexpected ways when one goes beyond the simplest projects.

  3. #28
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    14,140
    The INO is treated special to help use c/cpp without knowing ALL the details and make the build "work" without sweat - a very cool idea for beginners - or even quick lazy examples

    But underlying that is a real full featured gcc based c/cpp build environment that acts the same. And that Arduino.h is the connective piece for getting to the MCU layer like core_pins.h and the rest of the library linkage details to build.

    But having Arduino IDE as the common denominator makes getting started easy and forum code sharing easy, and yet is easily customizable to other build systems or ways. I use github.com/Defragster/Tset to do IDE Command line builds on my Windows system from my chosen editor and is much better for the process I use - but still fully IDE compatible in usage and in the binaries.

  4. #29
    Junior Member
    Join Date
    May 2021
    Location
    Sweden
    Posts
    11
    Yes, I mostly appreciate the simplicity of the Arduino IDE and the minimal configuration and setup necessary to get up and running. But sometimes some of the things that are hidden and make simple cases work effortlessly causes problems when the project grows and knowledge of what is intentionally hidden is required. I might take a look at your way of doing things at some point.

    My RTC is working fine (also with battery backup), but it drifts by a few seconds or so per day. I went looking for some kind of trim functionality, but found it neither in the Time library nor in the datasheet for the IMXRT1060, so I suppose there is no support for trimming. Maybe I could implement something by storing a time stamp in the non-volatile memory when I set the time and check it at power on and apply a correction based on how long the unit has been turned off. I can of course also correct regularly while powered on, but the use case is normally to be on for less than three hours, so a correction during that time is not particularly important.

  5. #30
    Is it possible to update the secure RTC via NTP or download, to today's date and then recall that in future boot ups without a battery connected so all my data logging dates are not Jan 1, 2019?

    Do I need a battery? What happens when the battery dies?

    It seems like the secure RTC, which can never be programmed to go backwards, should keep a forward moving time, which may be wrong in the absence of battery or NTP time, but won't be Jan 1, 2019 after every bootup. Or am I thinking this wrong?
    Last edited by TeensyWolf; 05-17-2021 at 02:18 AM. Reason: clarity

Posting Permissions

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