This tutorial show how to configure the STM32 RTC for reading Date and Time.
This example is based on NUCLEO-L476RG and use the ST-LINK Virtual Com to show on the PC the Date and Time.
We tested this example using Atollic (TrueSTUDIO ver.9.0.1) but is also possible import it in STM32CubeIDE.
Thanks the CUBE-MX is very easy transfer this example on others STM32.
For more info regarding RTC see the AN4759.
Below there is the schematic of the connection from PC to NUCLEO.
For communicate to the PC we use the UART2 that thanks to ST-LINK (present on the Nucleo Board) is visible via USB to the PC via Virtual Com.
For more info see this tutorial.
On your PC we suggest to use a TeraTerm that is an easy terminal emulator.
The configurations of TeraTerm must be:
The RTC quartz present on the NUCLEO board is: 32,768 KHz.
The configuration must be the same shown of below.
the divided clock is:
32768/((127+1)*(255+1)) = 1 Hz
every 1 second the MCU update the RTC second register.
Below there is the lines of code to insert between the label:
/* USER CODE BEGIN 3 */
….
….
/* USER CODE END 3 */
while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ HAL_RTC_GetTime(&hrtc, &stimeststuctureget, RTC_FORMAT_BIN); // Get Time HAL_RTC_GetDate(&hrtc, &sdateststuctureget, RTC_FORMAT_BIN); // Get Date uint8_t Time[3]; uint8_t Date[3]; Time[0] = stimeststuctureget.Hours; Time[1] = stimeststuctureget.Minutes; Time[2] = stimeststuctureget.Seconds; Date[0] = sdateststuctureget.Date; Date[1] = sdateststuctureget.Month; Date[2] = sdateststuctureget.Year; printf("%d_", Date[0]); printf("%d_", Date[1]); printf("%d - ", Date[2]); printf("%d:", Time[0]); printf("%d:", Time[1]); printf("%d \n\r", Time[2]); HAL_Delay(1000); } /* USER CODE END 3 */
On PC, using the TeraTerm, you must see something like below.
How to get the SW for this project
Please send us an email and ask us the password for: RTC-NUL476RG-ATOLLIC
Please specify also your country and your city, this are only for our personal statistics.
Get the SW clicking here, but remember to ask us the password for open it.
Note:
The project contain also the file for CUBE-MX
To import this project into your ATOLLIC TrueSTUDIO see this instructions.
Attention
NOTE:
- Use FIREFOX or CHROME for a clear view of the images present in this web site
- For enlarge the image press: CTRL +
For reduce the image press: CTRL –