WIP
прошивка по записи RTC для старых часов rally
This commit is contained in:
25
RTC_com.cpp
25
RTC_com.cpp
@@ -22,7 +22,7 @@ static int ledPin_Sync = A7; // Pin for valid RTC Sync
|
||||
static byte RTC_1HZ_PIN = cfg_pin_RTC_SQW; // Pin 3 = NANO INT1, RTC provides a 1Hz interrupt signal on this Pin
|
||||
static time_t last_sync_t = 0; // last sync
|
||||
static byte sync_err_hours = 4; // set to 4 for DS3231M, may be set to 8 for DS3231SN. Warning if no GPS sync after n hours, possible 0.1 sec error.
|
||||
bool SyncErr = true;
|
||||
bool SyncErr = true, RTC_SQW_LCD;
|
||||
|
||||
#include <DS3232RTC.h>
|
||||
DS3232RTC myRTC(0x68); // cfg_
|
||||
@@ -31,7 +31,7 @@ unsigned long RTCMillis; // blinking timer
|
||||
|
||||
void rtc_interrupt() {
|
||||
//Serial.print("DEBUG[INT] RTC interrupt "); Serial.println(micros());
|
||||
RTCMillis = millis();
|
||||
RTCMillis = micros();
|
||||
RTC_sec = true;
|
||||
}
|
||||
|
||||
@@ -51,34 +51,37 @@ void RTC_setup() {
|
||||
}
|
||||
|
||||
void RTC_loop() {
|
||||
//Serial.println("DEBUG[RTC_loop()] Start");
|
||||
if (RTC_sec) { // do after RTC PseudoPPS interrupt, without interrupt NO time/date to display
|
||||
DEBUG_PORT.println("DEBUG[RTC_loop()] RTC_sec: " + String(RTC_sec));
|
||||
DEBUG_PORT.println("DEBUG[RTC_loop()] RTCMillis: " + String(RTCMillis));
|
||||
DEBUG_PORT.println("DEBUG[RTC_loop()] millis: " + String(millis()));
|
||||
//DEBUG_PORT.println("DEBUG[RTC_loop()] RTC_sec: " + String(RTC_sec));
|
||||
//DEBUG_PORT.println("DEBUG[RTC_loop()] RTCMillis: " + String(RTCMillis));
|
||||
//DEBUG_PORT.println("DEBUG[RTC_loop()] millis: " + String(millis()));
|
||||
|
||||
lcd.setCursor(5, 0); RTC_SQW_LCD = !RTC_SQW_LCD;
|
||||
lcd.print((RTC_SQW_LCD) ? " " : ":");
|
||||
|
||||
RTC_sec = false; // clear flag
|
||||
digitalWrite(ledPin_PPS, LOW); // LED off
|
||||
time_t now_t = myRTC.get();
|
||||
if ((last_sync_t + (sync_err_hours * 3600)) < now_t) {
|
||||
SyncErr = true;
|
||||
digitalWrite(ledPin_Sync, LOW); // LED off
|
||||
//digitalWrite(ledPin_Sync, LOW); // LED off
|
||||
}
|
||||
Sec_Flip(now_t); // pass current datetime from RTC in UTC
|
||||
}
|
||||
else {
|
||||
NewSec = false;
|
||||
}
|
||||
if (millis() > (RTCMillis + 100)) { // do 100ms after PseudoPPS interrupt
|
||||
/*if (millis() > (RTCMillis + 100)) { // do 100ms after PseudoPPS interrupt
|
||||
digitalWrite(ledPin_PPS, HIGH); // LED on
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
void SetRTC(time_t t) {
|
||||
myRTC.set(t + 1); // the GPS NMEA output is 1 second behind at PPS !!
|
||||
last_sync_t = t;
|
||||
SyncErr = false;
|
||||
digitalWrite(ledPin_Sync, HIGH); // LED on
|
||||
//Serial.println("RTC set by GPS"); // debug
|
||||
//digitalWrite(ledPin_Sync, HIGH); // LED on
|
||||
DEBUG_PORT.println("RTC set by GPS"); // debug
|
||||
}
|
||||
|
||||
//End
|
||||
Reference in New Issue
Block a user