cancel
Showing results for 
Search instead for 
Did you mean: 

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

ZMust.1
Associate

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;

3 REPLIES 3
Pavel A.
Evangelist III

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

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

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

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);