Hi guys,
I'm working with a RTC peripheral on K64 with external 32,768Khz clock and the time counter doesn't seem to work. In other words, the RTC->TSR content stay the same. I verified on the XTAL output and the oscillator is working correctly.
There is my init :
rtc_config_t RTC_config = {
.wakeupSelect = false,
.updateMode = false,
.supervisorAccess = false,
.compensationInterval = 0x0U,
.compensationTime = 0x0U
};
dateTime_st.u16Year = 2021;
dateTime_st.u8Month = 11;
dateTime_st.u8Day = 24;
dateTime_st.u8Hour = 8;
dateTime_st.u8Min = 54;
dateTime_st.u8Sec = 00;
/* RTC initialization */
RTC_Init(RTC, &RTC_config);
/* Select RTC clock source */
RTC_SetClockSource(RTC); // Same as : RTC->CR |= RTC_CR_OSCE_MASK;
/* Stop RTC timer */
RTC_StopTimer(RTC); // Same as : RTC->SR |= ~RTC_SR_TCE_MASK;
/* Date and time initialization */
RTC_SetDatetime(RTC, (rtc_datetime_t *) &dateTime_st);
/* Start RTC timer */
RTC_StartTimer(RTC); // Same as : RTC->SR |= RTC_SR_TCE_MASK;
My clock sources and diagram configuration :
Any idea ?
Thank you by advance.
Best regards.
Mota
Hi @nxf77486,
Ok I'll research in the RTC configuration first. Thank you for these examples. I let you know.
Thank you.
Regards,
Mota
Hello @Mota ,
Thank you for your information I understand that your HW 32kHZ crystal is fine. Can you please check the RTC oscillator initialization that something has not been missing like the RTC_CR_OSCE bit (check if this is being set 1).
I also due recommend to try one of the SDK examples for the RTC.
Hi @nxf77486,
Thank you for your answer. RTC_CR_OSCE is well set to "1". I verified SR[TOF] and SR[TIF] bits and they are set to "0". Then the time counter should increment this value but it's not the case. The RTC_TSR counter stay always at the same value which is set at the beginning by RTC_SetDatetime().
There is the setup of my oscillator (It’s automaticaly genereted when I setup the clock sources) :
{
/* RTC clock gate enable */
CLOCK_EnableClock(kCLOCK_Rtc0);
if ((RTC->CR & RTC_CR_OSCE_MASK) == 0u) { /* Only if the Rtc oscillator is not already enabled */
/* Set the specified capacitor configuration for the RTC oscillator */
RTC_SetOscCapLoad(RTC, capLoad);
/* Enable the RTC 32KHz oscillator */
RTC->CR |= RTC_CR_OSCE_MASK;
}
/* Output to other peripherals */
if (enableOutPeriph) {
RTC->CR &= ~RTC_CR_CLKO_MASK;
}
else {
RTC->CR |= RTC_CR_CLKO_MASK;
}
/* Set the XTAL32/RTC_CLKIN frequency based on board setting. */
CLOCK_SetXtal32Freq(BOARD_XTAL32K_CLK_HZ);
/* Set RTC_TSR if there is fault value in RTC */
if (RTC->SR & RTC_SR_TIF_MASK) {
RTC -> TSR = RTC -> TSR;
}
/* RTC clock gate disable */
CLOCK_DisableClock(kCLOCK_Rtc0);
}
And it’s call in my main() by :
BOARD_InitBootClocks();
You will find below my RTC hardware configuration, I use VBAT too :
I don’t have FRDM-K64 board to test these kind of examples and I’m working with a MK64FX512xxx12 instead of MK64FN1M0xxx12..
Thank you.
Regards,
Mota