cancel
Showing results for 
Search instead for 
Did you mean: 

Configure STM32H753ZIT6 Internal RTC

Ematic
Associate II

Hi, I'm trying to configure the internal RTC on the STM32H753ZIT6 development board, but the RTC isn't functioning correctly—the time doesn't increment. The code was previously working with Ethernet, and I attempted to configure the internal RTC to work simultaneously. However, after making these changes, neither the RTC nor the Ethernet functions are working. I’ve attached the code and output file for reference.

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Super User

Here's your main loop code which prints the date and time:

  /* Infinite loop */
  for(;;)
  {
	  osDelay(100);
	  /* !! PBUF_RAM is critical for correct operation !! */
	  udp_buffer = pbuf_alloc(PBUF_TRANSPORT, strlen(message), PBUF_RAM);
	  if (udp_buffer != NULL) {
		memcpy(udp_buffer->payload, message, strlen(message));
		udp_send(my_udp, udp_buffer);
		printf("%d:%d:%d %d:%d:%d\r\n",gDate.Year,gDate.Month,gDate.Date,gTime.Hours,gTime.Minutes,gTime.Seconds);
		pbuf_free(udp_buffer);
	  }
  }

 

The code only reads date/time once, prior to entering the loop. You need to read it each time before you print it if you want it to be updated.

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

View solution in original post

3 REPLIES 3
TDK
Super User

Here's your main loop code which prints the date and time:

  /* Infinite loop */
  for(;;)
  {
	  osDelay(100);
	  /* !! PBUF_RAM is critical for correct operation !! */
	  udp_buffer = pbuf_alloc(PBUF_TRANSPORT, strlen(message), PBUF_RAM);
	  if (udp_buffer != NULL) {
		memcpy(udp_buffer->payload, message, strlen(message));
		udp_send(my_udp, udp_buffer);
		printf("%d:%d:%d %d:%d:%d\r\n",gDate.Year,gDate.Month,gDate.Date,gTime.Hours,gTime.Minutes,gTime.Seconds);
		pbuf_free(udp_buffer);
	  }
  }

 

The code only reads date/time once, prior to entering the loop. You need to read it each time before you print it if you want it to be updated.

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

Hi @TDK, I’ve modified my code based on your suggestion. The time is now incrementing, but I’ve noticed that the minutes increase when the seconds reach 89. Ideally, the minutes should increment when the seconds reach 59. I’ve attached the modified code and the output file for your reference.

 

Modified Code:

---------------------

 

/* Infinite loop */

for(;;)

{

HAL_RTC_GetTime(&hrtc, &gTime, RTC_FORMAT_BCD);

HAL_RTC_GetDate(&hrtc, &gDate, RTC_FORMAT_BCD);

osDelay(100);

/* !! PBUF_RAM is critical for correct operation !! */

udp_buffer = pbuf_alloc(PBUF_TRANSPORT, strlen(message), PBUF_RAM);

if (udp_buffer != NULL) {

memcpy(udp_buffer->payload, message, strlen(message));

udp_send(my_udp, udp_buffer);

printf("%d:%d:%d %d:%d:%d\r\n",gDate.Year,gDate.Month,gDate.Date,gTime.Hours,gTime.Minutes,gTime.Seconds);

pbuf_free(udp_buffer);

}

}

 

RTC Output2.PNG

waclawek.jan
Super User

You read time/date as BCD, i.e. 9 seconds is 0x09, 10 seconds is 0x10 = 17 - note the 9-to-17 transition in your printout; similarly 58 seconds is 0x58=88 (osDelay() plus the printing code results in slightly more than 1sec of delay between RTC readouts).

You want to use the binary readout facilities of Cube/HAL.

JW