Problem with Teensy 3.6 and RTC

Status
Not open for further replies.

daniel_tsonkov

New member
Sorry for my English...I have problem with internal RTC on Teensy 3.6. I connect battery CR2032 to VB and ground and use example code TymeTeensy3. However when disconnect power supply(USB) the RTC does't keep the time. What can be the problem.
 
As I see that sketch - it prints diagnostic info that is not included in post #1. Is it always setting the time?

Any chance of a dead battery - or +/- backwards or bad connection?
 
Battery in new. I tested connection from battery to board and it is OK. I set time with setTime(10,10,10,11, 12, 2017); on next upload I disable this row and time is 0 0 0 1 1 1970 now.
 
No. This is not the problem. The code which who I use is
/*
* TimeRTC.pde
* example code illustrating Time library with Real Time Clock.
*
*/

#include <TimeLib.h>

void setup() {
// set the Time library to use Teensy 3.0's RTC to keep time
//setSyncProvider(getTeensy3Time);
setTime(10,10,10,11, 12, 2017);

Serial.begin(115200);
/*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() {
if (Serial.available()) {
time_t t = processSyncMessage();
if (t != 0) {
Teensy3Clock.set(t); // set the RTC
setTime(t);
}
}

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();
}

time_t getTeensy3Time()
{
return Teensy3Clock.get();
}

/* code to process time sync messages from the serial port */
#define TIME_HEADER "T" // Header tag for serial time sync message

unsigned long processSyncMessage() {
unsigned long pctime = 0L;
const unsigned long DEFAULT_TIME = 1357041600; // Jan 1 2013

if(Serial.find(TIME_HEADER)) {
pctime = Serial.parseInt();
return pctime;
if( pctime < DEFAULT_TIME) { // check the value is a valid time (greater than Jan 1 2013)
pctime = 0L; // return 0 to indicate that the time is not valid
}
}
return pctime;
}

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);
}
 
I think you need (uncomment)
setSyncProvider(getTeensy3Time);


or just run unaltered File > Examples > Time > TimeTeensy3
 
And you also need to add
Teensy3Clock.set(now());
after
setTime(10,10,10,11, 12, 2017);
otherwise the RTC clock is not updated.
The setTime() function changes the clock in your running sketch, not in the RTC.
 
by the way you can also use

Code:
setSyncProvider(getTeensy3Time); 
 // this must be enabled for the sketch to load teensy's clock into the sketch time during boot, or else sketch wont have a time set even though RTC does.

I'm using this to pull time from an android root console with custom date string, so i can set the time whenever i want without reprogramming
 
Last edited:
Status
Not open for further replies.
Back
Top