4 RTC Periodic Interrupt
This code example shows how to use the PIT timing function of the RTC. The on-board LED will be toggled each second when the periodic interrupt occurs.
The source clock configuration for this particular example is the same as for the RTC overflow interrupt example. Enable the periodic interrupt by setting the PI bit in the RTC.PITINTCTRL register.
RTC.PITINTCTRL = RTC_PI_bm;
The PIT period is set in the RTC.PITCTRLA register. Enable the PIT by setting the PITEN bit in RTC.PITCTRLA.
RTC.PITCTRLA = RTC_PERIOD_CYC32768_gc | RTC_PITEN_bm;
For the interrupt to occur, the global interrupts must be enabled:
sei();
The Interrupt Service Routine (ISR) for the RTC PIT will toggle an LED in the example below:
ISR(RTC_PIT_vect) { RTC.PITINTFLAGS = RTC_PI_bm; LED0_toggle(); }
1
’ to it inside the ISR
function.An MCC generated code example for AVR128DA48, with the same functionality as the one described in this section, can be found here: