Skip to main content
ZMust.1
Associate
April 30, 2023
Question

How to update RTC time and date using Serial input USART?

  • April 30, 2023
  • 2 replies
  • 1779 views

Hi everyone, Could u help me how to update RTC time n date using serial Usart. Example code will help me to better understand , the date n time stored in this variable 

sTime.Hours = 0x00;

sTime.Minutes = 0x00;

sTime.Seconds = 0x00;

sDate.WeekDay = RTC_WEEKDAY_SATURDAY;

sDate.Month = RTC_MONTH_APRIL;

sDate.Date = 0x15;

sDate.Year = 0x23;

This topic has been closed for replies.

2 replies

Pavel A.
Super User
April 30, 2023

Do you want to program the RTC using CubeProgrammer over UART??

Tesla DeLorean
Guru
April 30, 2023

Collect bytes from the serial port​ to construct a string, break down with sscanf().

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
ZMust.1
ZMust.1Author
Associate
May 2, 2023

Hi , appreciate it, like this code?

while (1)

{

// Send a message to request the new date and time

HAL_UART_Transmit(&huart1, "Please enter the new date and time (YYYY-MM-DD HH:MM:SS):\r\n", strlen("Please enter the new date and time (YYYY-MM-DD HH:MM:SS):\r\n"), HAL_MAX_DELAY);

// Receive the new date and time from the user

HAL_UART_Receive(&huart1, usart_buffer, sizeof(usart_buffer), HAL_MAX_DELAY);

// Parse the received string to extract the year, month, day, hour, minute, and second values

int year, month, day, hour, minute, second;

sscanf(usart_buffer, "%d-%d-%d %d:%d:%d", &year, &month, &day, &hour, &minute, &second);