#include <DS3232RTC.h> // https://github.com/JChristensen/DS3232RTC
DS3232RTC rtc;
volatile uint32_t counter = 0;
volatile uint32_t counter2 = 0;
void isr_32768hz()
{
++counter;
}
void isr_sqw()
{
++counter2;
}
void setup()
{
Serial.begin( 115200 );
attachInterrupt( digitalPinToInterrupt( 2 ), isr_32768hz, FALLING );
attachInterrupt( digitalPinToInterrupt( 3 ), isr_sqw, FALLING );
rtc.begin();
/*rtc.squareWave( DS3232RTC::SQWAVE_1_HZ );
rtc.squareWave( DS3232RTC::SQWAVE_1024_HZ );
rtc.squareWave( DS3232RTC::SQWAVE_4096_HZ );
rtc.squareWave( DS3232RTC::SQWAVE_8192_HZ );
rtc.squareWave( DS3232RTC::SQWAVE_1_HZ );
rtc.squareWave( DS3232RTC::SQWAVE_NONE );
rtc.squareWave( DS3232RTC::SQWAVE_1_HZ );*/
rtc.set( 1664154792 );
/*delay( 1000 );
Serial.println( rtc.get() );
delay( 1000 );
rtc.set( 1664254792 );
delay( 1000 );
Serial.println( rtc.get() );
delay( 2000 );*/
}
void loop()
{
uint32_t now = millis();
static uint32_t past = now;
if ( now - past >= 1000 )
{
past = now;
//time_t now_rtc = rtc.get();
//Serial.println( now_rtc );
//Serial.println( counter * 1000000.0 / micros() );
//Serial.println( counter2 * 1000000.0 / micros() );
Serial.println( counter );
Serial.println( counter2 );
counter = 0;
counter2 = 0;
}
/*if ( counter >= 32768 )
{
Serial.println( now - past );
past = now;
counter = 0;
}*/
/*if ( counter2 >= 8192 )
{
Serial.println( now - past );
past = now;
counter2 = 0;
}*/
}