Sorry for the late reply, I needed work and leisure time. ![]()
There is something you have to apologize for first. ![]()
I said in the post above that capacitors aren't needed, but they may be needed.
Please connect your ATtiny1614 a 32.768kHz crystal and two capacitors of about 15pF.
And this code is the code to start the asynchronous timer on ATtiny1614 using an external crystal.
The interrupt increments the unsigned long variable myTime every second.
volatile unsigned long myTime;
void setup() {
rtcInit();
}
void loop() {
}
void rtcInit() {
noInterrupts();
CCP = CCP_IOREG_gc;
CLKCTRL.XOSC32KCTRLA = 0;
while (CLKCTRL.MCLKSTATUS & CLKCTRL_XOSC32KS_bm);
CCP = CCP_IOREG_gc;
CLKCTRL.XOSC32KCTRLA = CLKCTRL_CSUT_32K_gc | CLKCTRL_ENABLE_bm;
RTC.CLKSEL = RTC_CLKSEL_TOSC32K_gc;
while (RTC.PITSTATUS & RTC_CTRLBUSY_bm);
RTC.PITINTCTRL = RTC_PI_bm;
RTC.PITCTRLA = RTC_PERIOD_CYC32768_gc | RTC_PITEN_bm;
CPUINT.LVL1VEC = RTC_PIT_vect_num;
interrupts();
}
ISR(RTC_PIT_vect) {
myTime++;
}
I'm using megaTinyCore for compile this code.
You are free to write your own time management code using the myTime variable.