Ⅰ , overview
Today, we summarize the knowledge of RTC ( real Time clock) realtime clock, and simply summarize BKP.
the STM32 RTC module and clock configuration system (RCC_BDCR Register ) is in the fallback area, That is, when the system resets or wakes from Standby mode, The settings and time of the RTC remain unchanged.
Stm32f0 RTC f1 RTC f0 There are " date " and " time "register, that is, you can directly read the value inside the register, and
The software engineering provided in this article also contains a BKP module, which is mainly used for power-down to hold the RTC Value (first power-on initialization of the RTC, which is not initialized later). The routine is initialized at the first time with the RTC value as: 6 months , 5 days, seven weeks. 12:00:00(You can modify it yourself). Then read it every second and print it through the serial port. Here you can set the second interrupt without the software waiting for 1 seconds to read.
based on the principle of free sharing, if you feel that the content you share is useful to you, and want to know more about the article, please use the search " Embedddeveloper "or scan the QR code below, attention, will have more exciting content waiting for you.
Ⅱ, download
The article provides the "Software engineering" are on the hardware board to conduct multiple tests, and ensure that no problem before uploading to 360 cloud disk, please feel free to download the test, if there is a problem, please check your board if there is a problem.
St Standard Peripheral Library and reference manuals, data sheets, etc. can be downloaded from the St official website , you can also go to my 360 cloud disk download. There are several versions of the reference manual for the F0 series of chips (for F0 different chips), but there is a generic version, which is "stm32f0x128 reference manual V8 (English) 2015-07" recommended reference to this manual, later if you switch to a type of chip is also easy to understand.
Today's Software engineering (360 cloud disk):
Https://yunpan.cn/cSabGUUmvGUiN access password 8eee
STM32F0XX information can be downloaded from my 360 cloud disk:
https://yunpan.cn/cS2PVuHn6X2Bj access password 8c37
Ⅲ, preparatory work
It is recommended to prepare F0 Reference manuals and data sheets for easy access to relevant knowledge, please go to St official website or download to my cloud disk.
Today's summary of software engineering is based on the "TIM Basic Delay configuration Detailed process" modified, so you need to prepare the software engineering download. I always provide a tidy software for everyone to download, but, if you are a learner, suggest that you do one step at a time: Open Project -- new file (rtc.c rtc.h), Add related files to the project - Add source code.
Ⅳ,RTC principle
After the RTC clock comes in 1 seconds (1Hz), the RTC Clock Register (RTC_TR, RTC_DR) is not updated once, and the number we read changes. If the interrupt is configured, the interrupt will also respond when the corresponding event occurs. If an alarm is configured, the same value as the alarm setting also responds to the alarm.
Ⅴ, code description
①RCC Clock
The function is located under the BSP. c file;
RCC_APB1PERIPH_PWR clock power Management clock, RTC belongs to the backup management area. There is also a clock that is RTC clock, RTC Clock can LSI and LSE, I define a choice (see source code).
I'm personally accustomed to the first step of configuring the clock, ST 's officially provided routines also put the configuration clock in front. The configuration of the RCC clock is important, several times I just forgot to configure the corresponding RCC clock, let me find a long time problem, finally found that the RCC The clock is not configured.
Attention:
Peripheral clocks should not be arbitrarily added, such as:RCC_APB1 Peripherals do not configure in the rcc_apb2 Clock " such as:Rcc_apb2periphclockcmd (RCC _AHBPERIPH_DMA1, ENABLE); This can be compiled, but the wrong "
I warn the RCC clock every time because many people are having trouble with the software because of the clock, so remind more people to be careful about configuring RCC.
②RTC Configuration
The function is located under the RTC. c file;
Attention:
Here you need to define which clock to use, I offer engineering is using an internal LSI, and if you have an LSE External Clock , you can also define the use of an external clock.
③RTC initialization Configuration
The function is located under the RTC. c file;
Because RTC belongs to the back-up area, for convenience, here also uses the function of BKP, is to prevent the software to initialize the clock each time resets, here writes the fallback area BKP a flag bit, the first time initializes, later (as long as the Vbat, the fallback area a bit) does not need to reinitialize.
④ setting RTC Clock interface function
The function is located under the RTC. c file;
This function is my own encapsulation, mainly to the date and time of day wrapped together, convenient one-off operation.
⑤ read RTC Clock interface function
The function is located under the RTC. c file;
This function also encapsulates the date and time of day in a single operation. This knowledge of the structure of the proposal does not try to use the structure, application structure in C language is a more important piece.
Ⅵ, description
Perhaps your hardware chip is not to provide the chip inside the project, but stm32f0 chip software compatibility is very good, can be applied to F0 many other models of chips, even F2, F4 and other chips (see the manual, or personally test).
The software engineering provided in this article is based on the St standard Peripheral Library, rather than using STM32CUBEMX to establish the project. Personally feel that using ST's standard Peripheral library suitable for learners, STM32CUBEMX building engineering structure complex, for learners, especially beginners are estimated to be headache.
Today's project is based on the project "stm32f0xx_tim Basic Delay configuration Detailed process" modified, the above examples are summarized for reference only, if there is wrong, please understand.
Ⅶ, last
Attention, reply to "more content", will get more content (such as:UCOS instances, etc., constantly updated in ...) )。
If you like what I share, and you want to know more about it, please follow the public number at the beginning of the article, the new content continues to be updated, and more exciting content will appear later.
Read the original
STM32F0XX_RTC Real-Time clock configuration detailed procedure