Teensy 3.5 forgets the time of day

Status
Not open for further replies.

tarnerich

Member
Here's the source code, a modification of an Example:

/*
* TimeRTC.pde
* example code illustrating Time library with Real Time Clock.
*
*/

#include <TimeLib.h>

void setup() {
setTime(16,45,0,14,10,2017);

Serial.begin(9600);
while (!Serial); // Wait for Arduino Serial Monitor to open
delay(100);
if (timeStatus()!= timeSet) {
Serial.println("Unable to sync with the RTC");
} else {
Serial.println("RTC has set the system time");
}
}

void loop() {
digitalClockDisplay();
delay(1000);
}

void digitalClockDisplay() {
// digital clock display of the time
Serial.print(hour());
printDigits(minute());
printDigits(second());
Serial.print(" ");
Serial.print(day());
Serial.print(" ");
Serial.print(month());
Serial.print(" ");
Serial.print(year());
Serial.println();
}

void printDigits(int digits){
// utility function for digital clock display: prints preceding colon and leading 0
Serial.print(":");
if(digits < 10)
Serial.print('0');
Serial.print(digits);
}


When the setTime() call is not commented out, everything works as expected:

RTC has set the system time
16:45:12 14 10 2017
16:45:13 14 10 2017
16:45:14 14 10 2017
... etc

But when I do comment it out, the Teensy doesn't know the time any more:

Unable to sync with the RTC
0:00:04 1 1 1970
0:00:05 1 1 1970
0:00:06 1 1 1970
... etc

I have a coin cell feeding 3.0V to the Vbat pin. What am I missing?
 
Last edited:
You need to tell the Time lib to use Teensy's RTC. Use setSyncProvider. Click File > Examples > Time > TimeTeensy3 to see how it's done.
 
Status
Not open for further replies.
Back
Top