2022-03-30 12:03 PM
2022-03-30 12:24 PM
Chip? Is RTC clock enabled? Show code.
2022-03-30 12:35 PM
Which STM32?
The procedure is:
I don't use Cube/LL, but it's open source so you can find easily the respective LL function/macro names yourself, if you want to stick to them.
JW
2022-03-31 04:18 AM
Good morning (in Brazil).
I'm using STM32F407ZET6 and CubeMX to configure.
Yes, I've been activated the RTC in CubeMX.
The situation is: The time are running. My problem is configurating the time / date.
Follow the code:
LL_RTC_DisableWriteProtection(RTC);
LL_RTC_EnableInitMode(RTC);
LL_RTC_TIME_SetHour(RTC, Hours_BCD);
LL_RTC_TIME_SetMinute(RTC, Minutes_BCD);
LL_RTC_TIME_SetSecond(RTC, Seconds_BCD);
LL_RTC_DATE_SetDay(RTC, Day_BCD);
LL_RTC_DATE_SetMonth(RTC, Month_BCD);
LL_RTC_DATE_SetYear(RTC, Year_BCD);
LL_RTC_DisableInitMode(RTC);
LL_RTC_EnableWriteProtection(RTC);
2022-03-31 04:29 AM
Good morning (in Brazil).
Which STM32? - STM32F407ZET6
I've been tried both HAL and LL drivers to configure the time / date. With HAL driver I got success in configuring, but the values resets when I turn the MCU off. But with the LL driver I can't even configure date nor time.
The code is above.
2022-03-31 05:02 AM
> The code is above.
Check if that code fulfills *all* steps I mentioned above.
In debugger, step through and check the respective registers/bits if they contain what they should.
JW
2022-03-31 05:08 AM
RCC->APB1ENR |= RCC_APB1ENR_PWREN; // anywhere before calling the below function
void RtcSetTime(uint_least8_t h, uint_least8_t m, uint_least8_t s) {
uint32_t i;
// unlock write to backup domain
PWR->CR |= PWR_CR_DBP;
// unlock RTC write protection after power-on reset
RTC->WPR = 0xCA;
RTC->WPR = 0x53;
// set to init mode and wait until in sync -- it should take around 2 RTCCLK clocks
RTC->ISR |= RTC_ISR_INIT;
for (i = 0; i < 10000; i++) if ((RTC->ISR AND RTC_ISR_INITF) != 0) break;
// set time
RTC->TR = (TimeToBcdTime(h, m, s, 0)).all; // modeAmPm is always 0 here, as we always set RTC in 24h format!
// exit init mode - this should start the RTC
RTC->ISR &= (uint32_t)~RTC_ISR_INIT;
// maybe we should wait for resyc here - hw had cleared RSF bit during init mode, we should be waiting until it gets set by hardware, to ensure that subsequent reading will return valid time, but let's defer that to the routine which desires to read out the time
// reenable the write protection for RTC registers */
RTC->WPR = 0xFF;
// lock write to backup domain
PWR->CR &= ~PWR_CR_DBP;
}
This is actually used to set time on an STM32F407.
JW