cancel
Showing results for 
Search instead for 
Did you mean: 

Nucleo H723 RTC under VBAT powering

FCamp.1
Associate III

Hello,

I have set an RTC on a Nucleo H7 board and i I am powering it via VBAT pin when i switch off the VDD on the board. I have removed the 0Ohm connector from the SB52 and everything since working fine. When I reset the board for instance and I keep in reset for 10 sec, for instance, when i restart the board the RTC has the timing set plus 10 secs which is the behaviour requested. The RTC is ticking when the board is in reset.

However if i unplug the VDD and I wait for instance 1 minute, as soon as I replug the RTC is keeping correctly the time but is not advancing; it stands still at the timing when i have unplug the VDD.

This is the only code i put in:

/**
  * @brief RTC Initialization Function
  * @param None
  * @retval None
  */
static void MX_RTC_Init(void)
{
 
  /* USER CODE BEGIN RTC_Init 0 */
 
	/*
	 * Actions #1 and #2 are needed to resolve the default initialization
	 * of the RTC coming from the MX
	*/
 
  /* USER CODE END RTC_Init 0 */
 
  RTC_TimeTypeDef sTime = {0};
  RTC_DateTypeDef sDate = {0};
 
  /* USER CODE BEGIN RTC_Init 1 */
 
  /* USER CODE END RTC_Init 1 */
 
  /** Initialize RTC Only
  */
  hrtc.Instance = RTC;
  hrtc.Init.HourFormat = RTC_HOURFORMAT_24;
  hrtc.Init.AsynchPrediv = 127;
  hrtc.Init.SynchPrediv = 255;
  hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;
  hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
  hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
  hrtc.Init.OutPutRemap = RTC_OUTPUT_REMAP_NONE;
  if (HAL_RTC_Init(&hrtc) != HAL_OK)
  {
    Error_Handler();
  }
 
  /* USER CODE BEGIN Check_RTC_BKUP */
 
  // #1
  // Get the time stamp from the RTC which is powered via external battery on VBAT
  // store the value to the backup register
 
	HAL_RTC_GetTime(&hrtc, &sTime, RTC_FORMAT_BIN);
	HAL_RTC_GetDate(&hrtc, &sDate, RTC_FORMAT_BIN);
 
	uint32_t timeStamp = 0;
	timeStamp |= (sTime.Hours << 16) | (sTime.Minutes << 8) | sTime.Seconds;
 
	HAL_RTCEx_BKUPWrite(&hrtc, RTC_BKP_DR1, timeStamp);
 
	uint32_t dateStamp = 0;
	dateStamp |= (sDate.Date << 16) | (sDate.Month << 8) | sDate.Year;
 
	HAL_RTCEx_BKUPWrite(&hrtc, RTC_BKP_DR2, dateStamp);
 
  /* USER CODE END Check_RTC_BKUP */
 
  /** Initialize RTC and set the Time and Date
  */
  sTime.Hours = 0;
  sTime.Minutes = 0;
  sTime.Seconds = 0;
  sTime.DayLightSaving = RTC_DAYLIGHTSAVING_ADD1H;
  sTime.StoreOperation = RTC_STOREOPERATION_RESET;
  if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BIN) != HAL_OK)
  {
    Error_Handler();
  }
  sDate.WeekDay = RTC_WEEKDAY_THURSDAY;
  sDate.Month = RTC_MONTH_NOVEMBER;
  sDate.Date = 30;
  sDate.Year = 22;
 
  if (HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BIN) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN RTC_Init 2 */
 
  // #2
  // Get the value from the backup register and set it to the RTC
 
	sTime.Hours		= 	(uint8_t)((HAL_RTCEx_BKUPRead(&hrtc, RTC_BKP_DR1) & 0xFF0000) >> 16);
	sTime.Minutes 	= 	(uint8_t)((HAL_RTCEx_BKUPRead(&hrtc, RTC_BKP_DR1) & 0x00FF00) >> 8);
	sTime.Seconds 	= 	(uint8_t)(HAL_RTCEx_BKUPRead(&hrtc, RTC_BKP_DR1) & 0x0000FF);
 
	sDate.Date 		=	(uint8_t)((HAL_RTCEx_BKUPRead(&hrtc, RTC_BKP_DR2) & 0xFF0000) >> 16);
	sDate.Month 	= 	(uint8_t)((HAL_RTCEx_BKUPRead(&hrtc, RTC_BKP_DR2) & 0x00FF00) >> 8);
	sDate.Year 		=	(uint8_t)(HAL_RTCEx_BKUPRead(&hrtc, RTC_BKP_DR2) & 0x0000FF);
 
	HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BIN);
	HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BIN);
 
	HAL_RTC_GetTime(&hrtc, &sTime, RTC_FORMAT_BIN);
	HAL_RTC_GetDate(&hrtc, &sDate, RTC_FORMAT_BIN);
 
  /* USER CODE END RTC_Init 2 */
 
}

I have added action #1 and #2 just to workaround the MX code generated.

The battery is connected coupled with 2 caps for 1uf and 100nf as requested.

The RTC is clocked by the LSE.

It seems something is wrong in the ticking of the RTC as soon as the VDD is off but i can't figure out what it is.

Can someone help me please?

Thanks,

Filippo

6 REPLIES 6

I wonder where do you have this nonsense from. This is even bigger nonsense than we are used to see here, coming from clicking in CubeMX, so you must've found it somewhere on the net or what. I'm not even trying to understand if this is the cause of the symptoms you've described, or something else.

Ditch Cube. Read RM. Write your own code. Initialize RTC only once in the battery lifetime.

JW

You know someone once said that there are never stupid questions but only stupid answers. I think you perfectly confirmed this sentence. Bravo!

aKrug.1
Associate

Hello,

try to verify the initialization of the LSE, it must be stable before to run the RTC.

Cheer and good luck!

a.

Hello a.

thanks. I think it's an interesting point.

Gonna give it a check!

Filippo

AScha.3
Chief

+

set LSE drive level to high.

If you feel a post has answered your question, please click "Accept as Solution".

Instead of being an "offended" snowflake, read the link given by Jan. And the current workaround is indeed a nonsense. Just put a check and return in the "RTC_Init 0" section.

Not about your topic, but... there are hundreds of topics in this forum, which are a direct proof that there are stupid questions! This quote could be more accurate:

https://i1.wp.com/i.kym-cdn.com/photos/images/original/001/192/978/b5f.jpg