I have been trying to sleep my ATTiny414 for 10 minutes after which it will wake up and take a measure of a frequency using a frequency counter and go back to sleep. I tried implementing a for loop after wake up from interrupt to put the UCON to sleep till 4 seconds ( for testing purposes) but it seems to not wake up at all.
Following is the code i used for the PIT Interrupts
int PIT_Counter = 0;
void EnablePIT()
{
RTC.PITINTCTRL = RTC_PI_bm;
RTC.PITCTRLA = RTC_PERIOD_CYC32768_gc | RTC_PITEN_bm;
SLPCTRL.CTRLA |= SLPCTRL_SMODE_PDOWN_gc;
SLPCTRL.CTRLA |= SLPCTRL_SEN_bm;
sleep_cpu();
}
// PIT Wake-Up Interrupt
ISR(RTC_PIT_vect)
{
RTC.PITINTFLAGS = 1;
if (PIT_Counter < 4)
{
PIT_Counter = PIT_Counter + 1;
EnablePIT();
}
else
{
PIT_Counter = 0;
RTC.PITINTCTRL = ~RTC_PI_bm;
PORTA.DIRSET = PIN4_bm; // Make LED on PA4 an output
PORTA.PIN4CTRL = PORT_INVEN_bm; // Invert output
ADC0.CTRLA |= ~ADC_ENABLE_bm;
Wire.begin();
TCDSetup();
RTCSetup();
EvsysSetup();
}
}
I call EnablePIT() to re-enable and sleep the UCON after I send a value to the I2C.
I'm reading the output using I2C and I dont recieve any values sadly. Any clues where I may be wrong?