cancel
Showing results for 
Search instead for 
Did you mean: 

RTC not working on Vbat

Karakala
Associate II

Hi everyone,

I am using a STM32H563RG and I need the RTC to work even if the VDD is powered off. To do that, I am plugging a battery on the VBAT pin to power the RTC and the Backup domain. But I tested it and it seems the RTC is stopped and the backup domain is cleared when VDD is powered off.

Here is my initialisation code :

/* Configure the system clock */

SystemClock_Config();

/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */


/* Initialize all configured peripherals */

MX_GPIO_Init();
MX_GPDMA1_Init();
MX_ICACHE_Init();
MX_CRC_Init();
MX_SPI1_Init();
MX_TIM3_Init();
//MX_RTC_Init();
MX_ADC1_Init();
MX_ADC2_Init();
MX_TIM2_Init();
MX_FileX_Init();
MX_IWDG_Init();
MX_TouchGFX_Init();

/* USER CODE BEGIN 2 */

LL_PWR_EnableBkUpRegulator();
LL_PWR_EnableBkUpAccess();


if(LL_RTC_BKP_GetRegister(RTC,LL_RTC_BKP_DR0) == 0x32F2){ //Read Backup register to see if it was previously written

  RTC_Datas.RTC_initialized = 1; //Set flag
  GPIO_Set(Led_orang); //Turn Orange LED On

}

else{ //If not previously written

  RTC_Datas.RTC_initialized = 0; //Clear flag
  MX_RTC_Init(); //Call RTC_Init() to initialise RTC

}

RTC_Datas.Jour = __LL_RTC_CONVERT_BCD2BIN(LL_RTC_DATE_GetDay(RTC)); //Read day
RTC_Datas.Mois = __LL_RTC_CONVERT_BCD2BIN(LL_RTC_DATE_GetMonth(RTC)); //Read month
RTC_Datas.Annee = __LL_RTC_CONVERT_BCD2BIN(LL_RTC_DATE_GetYear(RTC)) + 2000; //Read year

RTC_Datas.Minute = __LL_RTC_CONVERT_BCD2BIN(LL_RTC_TIME_GetMinute(RTC));//Read minutes
RTC_Datas.Heure = __LL_RTC_CONVERT_BCD2BIN(LL_RTC_TIME_GetHour(RTC)); //Read hours

 

The value 0x32F2 is written in the BKR0 backup register by the MX_RTC_Init() function. It should stay written in it even if there is a µC reset (with VBAT at 3,3V). I check if the RTC was previously initialised by reading this backup register : if I read 0x32F2, it means it was initialised and a Orange LED is turned ON. However, after a reset (performed by the VDD being powered off then powered on right away), the Orange LED doesn't turn ON and the RTC values are reinitialised.

What I made sure of :

  • RTC is clocked on LSE
  • LSE drive capabilty is HIGH
  • TAMP secure zone is deactivated
  • VBAT stays at approx. 3V3 during reset
  • LSE still on after reset
  • BREN bit of PWR->BDCR is set (to enable backup regulator)

It seems there is no Backup domain reset happening since the RTCSEL bit field of RCC->BDCR stays at 1 after reset ( it would be equal to 0 after a bakcup domain reset).

I therefore have three questions :

1) Are the RTC values saved in the backup domain or it is two different things ?

2) Is my test method correct to prove the Backup register is cleared ?

3) What could clear the Backup register and the RTC values reset ?

1 REPLY 1
Andrew Neil
Super User

Welcome to the forum.

Please see: How to write your question to maximize your chances to find a solution for best results.

In particular, please give details of your hardware.

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.