Internal RTC in STM32
Most of the STM32 devices have RTC (Real Time Clock) built in which can keep the track of the current time and date. RTC can be used for chronometers, alarm clocks, watches, small electronic agendas, and many other devices and today we are going to learn HOW to access internal RTC in STM32.
We will see how to set up the time, Getting the time and displaying it on the LCD and also How to use the alarm feature. So let’s begin the Process…
The clock configuration is as follows
Next go to configuration tab and click on RTC
Generate the project and open it.
We are going to set the time and date in the program itself. So first let’s write a function to set the time and date
The time should be entered in a HEX format. The time above is 10:20:30 and the date is 09-Aug-2018.
Also note that
is a backup register and is used to store time and date. It’s use is explained in the video attached in the last tab.
The value (0x32F2) is just a random value. you can use some other value also.
Now let’s write a function to read the time and date
The above function is self explanatory. sprintf is used to convert the values into the char so that we can display it on the LCD
display_time on LCD
The following function is used to set ALARM and we will also write another function to be called when this alarm get triggered.
ALARM Event Callback Function
This function is called when the alarm gets triggered and it will turn ON the LED at PA5.
- #Modbus 1. STM32 Master Reads Holding and Input Registers October 1, 2022
- MODBUS PROTOCOL 101 September 29, 2022
- RS485 Module and STM32 September 23, 2022
- FDCAN in Normal Mode || STM32H7 September 15, 2022
- STM32 FDCAN in Loopback Mode August 19, 2022
- I2C in ESP32 || ESP-IDF || LCD 1602 July 15, 2022