2023-04-27 12:18 AM
2023-04-29 04:23 AM
Thanks JTP.
unfortunately none of them didn't help me.
2023-04-29 04:28 AM
Thanks AScha.3.
when I do it, time of RTC doesn't work.
2023-04-29 04:49 AM
Thanks AScha.3.
when I comment this function, time of RTC doesn't work properly.
2023-04-29 04:56 AM
Thanks AScha.3.
When I comment this ( // MX_RTC_Init();), time of RTC doesn't work.
2023-04-29 05:03 AM
ok, but what about the backup ram ? reset?
+ Vbat battery has to be always connected !
2023-04-29 05:03 AM
Seems that your are using actually LSI as RTC clock source and it is not powered with backup voltage. Maybe easiest to renerate code from cube... or then change in main.c function void SystemClock_Config(void):
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE|RCC_OSCILLATORTYPE_LSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.LSEState = RCC_LSE_ON;
and in the stm32f4xx_hal_msp.c
void HAL_RTC_MspInit(RTC_HandleTypeDef* hrtc)
{
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
if(hrtc->Instance==RTC)
{
/* USER CODE BEGIN RTC_MspInit 0 */
/* USER CODE END RTC_MspInit 0 */
/** Initializes the peripherals clock
*/
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC;
PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
{
Error_Handler();
}
/* Peripheral clock enable */
__HAL_RCC_RTC_ENABLE();
/* USER CODE BEGIN RTC_MspInit 1 */
/* USER CODE END RTC_MspInit 1 */
}
}
LSI -> LSE
2023-04-29 06:45 AM
RTC_BKP_DR is reset when unplugging power while the vbat pin is connected to CR1220 battery.
2023-04-29 06:56 AM
I did all configurations that you mentioned but I will do it again.
changing the cube package for stm32f4 can be effective (I'm using ver1.27)?
2023-04-29 10:05 AM
OK, it should work pretty much just out-of-box. Just set the clock 32KHz configuration to LSE ja and enable RTC.
One more thing, when you try to comment out the MX_RTC_Init(), maybe your hrtc- struct was not initialized to point to RTC module, since it is initialized in MX_RTC_Init : hrtc.Instance = RTC;
So remember to init hrtc-struct somewhere else if not run MX_RTC_Init().
2023-04-29 11:13 AM
I suspect the same problem we have discussed some time ago: if you use the HAL and let CubeMX generate your skeleton programme, the default time information is always set to the default value after a reset.
Background of this somewhat debatable decision: when developing programmes and debugging, a defined basic state should be set up after a reset.
The link above suggests a method for deactivating the reset of the RTC. However, it should then also be ensured that the RTC already has a basic state and is buffered via VBAT.
Hope this helps, even if it looks (and is) a bit makeshift?
Regards
/Peter