Code: Select all
#define Timer_int_PIN 13 // GPIO13
volatile bool timer_int = false; // DS3231 Timer 1 Hz interrupt signalling flag
volatile int seconds_since_interrupt = 0;
volatile bool LED_state;
void IRAM_ATTR isr_Timer1() { // This interrupt fires at a 1Hz rate
timer_int = true; // The IRAM_ATR neither causes or resolves the problem.
seconds_since_interrupt++;
LED_state = !LED_state;
digitalWrite(LED,LED_state);
return;
setup() {
attachInterrupt(Timer_int_PIN, isr_Timer1, FALLING);
}
void loop() { // Top section maintains an internal 24h clock
if (timer_int) { // If RTC 1Hz clock interrupt has been triggered then do timer service
DS3231RTC.checkIfAlarm(1); // Clear Alarm 1 flag in the RTC chip
timer_int = false; // reset timer interrupt flag
seconds_since_interrupt = 0;
if (tminfo.tm_sec > 59) { // each minute
tminfo.tm_sec = tminfo.tm_sec - 60; // in case the delay from interrupt to this code was > 1 sec and < 60 sec
tminfo.tm_min++;
if (tminfo.tm_min > 59) { // each hour
tminfo.tm_min = 0;
tminfo.tm_hour++;
if (tminfo.tm_hour > 23) { // each day at midnight
tminfo.tm_hour = 0; // Run a local 24h clock, updated from the RTC once a day
get_RTC_time(); // i.e. the RTC is only called once a day at midnight to update the time
}
}
}
} // end of timer interrupt service
if(BTPort.available()) { // BTPort is a serial connection over Bluetooth classic.
c = BTPort.read();
switch (c) {
// several other cases..... Here is one:
case 'm': kbGetMonth(); // Get month and year from BT terminal
extractMonthData(); // extract data from SD card
break;
} // switch
} // if BTPort
} // loop
Thank you for your time, will