Arduino RTC DS3231干扰中断

时间:2019-09-19 15:31:47

标签: arduino arduino-c++

我正在使用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)
}

0 个答案:

没有答案