RTC Time Reset on Due Restart
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);
}
}
Yes I know, there are 2 problems at this piont.
- The Due has no Backupbatterie so there will no data's stored if he is powerless.
- 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
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!
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.
Did you want to set an unixtime oder date and time from compiler?
Can you post the complete sketch?
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 [email protected] wrote:
Did you want to set an unixtime oder date and time from compiler?
— Reply to this email directly or view it on GitHub https://github.com/MarkusLange/Arduino-Due-RTC-Library/issues/4#issuecomment-113790170 .
Can I get the complete sketch
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 [email protected] wrote:
Can I get the complete sketch
— Reply to this email directly or view it on GitHub https://github.com/MarkusLange/Arduino-Due-RTC-Library/issues/4#issuecomment-113801117 .
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.
New version up should work for you purpose
Downloaded the new lib, and tested (same as my previous post). rtc_clock.set_clock(0,0) still prints 2070.
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