我正在使用Arduino Mega2650。连接了DS3231型实时时钟(RTC)后,我的计数器停止可靠地工作。 RTC连接到引脚20(SLA)和引脚21(SCL)。这是代码。
#include <DS3232RTC.h>
volatile int counter1;
int pin2 = 2; //ci
void setup() {
Serial.begin(115200);
setSyncProvider(RTC.get); // Library function to get the time from the RTC module.
if (timeStatus() != timeSet) {
Serial.println("System Time Cannot be Set. Check Connections.");
} else {
Serial.println("System Time is Set.");
}
}
void IRQcounter1() {
counter1++;
}
void loop() {
attachInterrupt(pin_irq1, IRQcounter1, RISING);
delay(25);
detachInterrupt(pin2);
myTime = RTC.get();
Serial.print(String(counter1) + "," + myTime)
}