// rtc interrupt code ..............................................
using callback_t = void(void);
void setupRTC_Interrupt(callback_t isr)
{
// disable periodic interrupt
SNVS_HPCR &= ~SNVS_HPCR_PI_EN;
while ((SNVS_HPCR & SNVS_HPCR_PI_EN)) {} // spin until PI_EN is reset...
// set interrupt frequency to 1Hz
SNVS_HPCR = SNVS_HPCR_PI_FREQ(0b1111); // once per second, change for other frequencies (see IMXRT1062 manual for possible values)
// enable periodic interrupt
SNVS_HPCR |= SNVS_HPCR_PI_EN;
while (!(SNVS_HPCR & SNVS_HPCR_PI_EN)) {} // spin until PI_EN is set...
// attach a callback
attachInterruptVector(IRQ_SNVS_IRQ, isr);
NVIC_SET_PRIORITY(IRQ_SNVS_IRQ, 255); // lowest priority
NVIC_ENABLE_IRQ(IRQ_SNVS_IRQ);
}
void RTC_ISR()
{
SNVS_HPSR |= 0b11; // reset interrupt flag
// do whatever needs to be done in the ISR...
digitalToggleFast(LED_BUILTIN);
asm("dsb"); // wait until flag is synced over the busses to prevent double calls of the isr
}
//............................................................
void setup()
{
pinMode(LED_BUILTIN, OUTPUT);
setupRTC_Interrupt(RTC_ISR);
}
void loop()
{
}
IOMUXC_SW_MUX_CTL_PAD_GPIO_AD_B0_00 = 2; // AD_B0_00 = REF_CLK_32
To turn on the 32 kHz clock output at that pin, use this:
Code:IOMUXC_SW_MUX_CTL_PAD_GPIO_AD_B0_00 = 2; // AD_B0_00 = REF_CLK_32
Details on page 472-473.
Oh, great! I'm waiting for a radio chip that needs exactly these 32768khz. That saves a pin or the crystal
it does not have to be 32768Hz - it takes almost anything..
tone(0, 32000); // Output 32kHz on Pin 0 - connect Teensy Pin 0 with RCLK on Si4735
si4735.setup(RESET_PIN, -1, FM_FUNCTION, SI473X_ANALOG_AUDIO, 0);
si4735.setRefClockPrescaler(1, 0);
si4735.setRefClock(32000);
But this works