Skip to content

RTC Time Reset on Due Restart #4

Open

Description

@JamesSidell

I noticed that if the Due is programmed using this library, the date will only be correct if the unit is not powered down. If you program the time in by uncommenting out the rtc_clock.set lines to 'burn' the current time to the RTC, then commen them out to burn the rest of the program onto the chip, then upon restart of the unit the time reverts to 1/1/2007 0:0:0.

Expected behavior is rtc_clock.get should return the current time, regardless of how long the due has been powered down. My test code is below, and it's likely that I'm doing something wrong or not understanding something about the library!

include <SPI.h>

include <SD.h>

include <rtc_clock.h>

// Select the Slowclock source
RTC_clock rtc_clock(XTAL);

unsigned int currentTime = 0;
unsigned int prevTime = 0;
unsigned int prevSerialTime = 0;
/////////////////////////////////////////////////////////////////////////
void setup() {
Serial.begin(9600);

//rtc_clock.init();
//rtc_clock.set_time(TIME);
//rtc_clock.set_date(DATE);
//Only run these once to setup the RTC clock (assuming the clock has a good battery)
}
/////////////////////////////////////////////////////////////////////////
void loop() {
currentTime = millis();
if (currentTime - prevSerialTime > 5000) {
prevSerialTime = currentTime;

  String dataString = "";
  dataString += rtc_clock.get_months();
  dataString += "/";
  dataString += rtc_clock.get_days();
  dataString += "/";
  dataString += rtc_clock.get_years();
  dataString += " ";
  dataString += rtc_clock.get_hours();
  dataString += ":";
  dataString += rtc_clock.get_minutes();
  dataString += ":";      
  dataString += rtc_clock.get_seconds();
  dataString += ",";
  dataString += "data1";
  dataString += ",";
  dataString += "data2";
  Serial.println(dataString);
}

}

Activity

  1. MarkusLange commented on Apr 21, 2015

    @MarkusLange
    Owner

    Yes I know, there are 2 problems at this piont.

    1. The Due has no Backupbatterie so there will no data's stored if he is powerless.
    2. The Due does reset with the NRSTB pin. This resets the full chip with all backup regions including RTC, RTT and SC. Only if the reset is done with the NRST pin will these regions stay with their old values. And the value what you get then is the startvalue of the register, everytime
  2. JamesSidell commented on Apr 21, 2015

    @JamesSidell
    Author

    OK, I thought it was something I was doing wrong in the sketch! Thanks for putting this library together, and I'll look for changes in the future!

  3. kapyaar commented on Jun 19, 2015

    @kapyaar

    If I do
    rtc_clock.set_clock(0, 0);

    then the year is printing as 2070 instead of 1970. I am using Arduino IDE 1.6.4.

  4. MarkusLange commented on Jun 20, 2015

    @MarkusLange
    Owner

    Did you want to set an unixtime oder date and time from compiler?

    Can you post the complete sketch?

  5. kapyaar commented on Jun 20, 2015

    @kapyaar

    I want to set unitTime (0). When I start the code, it will check to sync
    with time from the internet. If not reachable, I want to to set it as
    unitTime 0, which should be the 1970 year, etc.

    I doubt that it has something to do with SECONDS_FROM_1970_TO_2000

    Bcz if I set the time 946684800, the year shows ok as 2000, but if I set it
    as 946684799, the year shows as 2099 instead of 1999.

    Avarachan

    On Sat, Jun 20, 2015 at 1:08 PM, MarkusLange notifications@github.com
    wrote:

    Did you want to set an unixtime oder date and time from compiler?

    —
    Reply to this email directly or view it on GitHub
    #4 (comment)
    .

  6. MarkusLange commented on Jun 20, 2015

    @MarkusLange
    Owner

    Can I get the complete sketch

  7. kapyaar commented on Jun 20, 2015

    @kapyaar

    I am playing with one of your example sketches
    Due_RTC_Simple_Sample_oneline_time_and_date.ino
    https://github.com/MarkusLange/Arduino-Due-RTC-Library/blob/master/examples/Due_RTC_Simple_Sample_oneline_time_and_date/Due_RTC_Simple_Sample_oneline_time_and_date.ino

    My tests

    void setup() {
    Serial.begin(115200);
    rtc_clock.init();
    //rtc_clock.set_clock(DATE, TIME);
    //rtc_clock.set_clock(0,0);
    //rtc_clock.set_clock(946684799,0);
    rtc_clock.set_clock(946684800,0);
    }

    Avarachan

    On Sat, Jun 20, 2015 at 2:37 PM, MarkusLange notifications@github.com
    wrote:

    Can I get the complete sketch

    —
    Reply to this email directly or view it on GitHub
    #4 (comment)
    .

  8. MarkusLange commented on Jun 21, 2015

    @MarkusLange
    Owner

    Ah I understand, yes you are right, I will rewrite it so that so that it works without the define SECONDS_FROM_1970_TO_2000 that it will count the ticks from the 1.01.1970 to the actuall date, so that every date from the start of the unixtime will shown correct.

  9. MarkusLange commented on Jun 22, 2015

    @MarkusLange
    Owner

    New version up should work for you purpose

  10. kapyaar commented on Jun 23, 2015

    @kapyaar

    Downloaded the new lib, and tested (same as my previous post). rtc_clock.set_clock(0,0) still prints 2070.

  11. MarkusLange commented on Jun 23, 2015

    @MarkusLange
    Owner

    I will take a closer look at the end of the week, may I need to seperate there something with set_clock you can set ntp and unixtime looks like it doesn't work the way I want

  12. colesnicov commented on Jan 25, 2018

    @colesnicov
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions