{"id":1615,"date":"2023-03-09T05:03:09","date_gmt":"2023-03-09T05:03:09","guid":{"rendered":"https:\/\/blog.embeddedexpert.io\/?p=1615"},"modified":"2023-03-09T05:03:11","modified_gmt":"2023-03-09T05:03:11","slug":"working-with-stm32-and-internal-rtc-part-1-introduction","status":"publish","type":"post","link":"https:\/\/blog.embeddedexpert.io\/?p=1615","title":{"rendered":"Working with STM32 and internal RTC Part 1: Introduction"},"content":{"rendered":"\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img decoding=\"async\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/03\/AdobeStock_139809605-1024x1024.jpeg\" alt=\"\" class=\"wp-image-1616\" width=\"NaN\" height=\"NaN\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/03\/AdobeStock_139809605-1024x1024.jpeg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/03\/AdobeStock_139809605-300x300.jpeg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/03\/AdobeStock_139809605-150x150.jpeg 150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/03\/AdobeStock_139809605-768x768.jpeg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/03\/AdobeStock_139809605-1536x1536.jpeg 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/03\/AdobeStock_139809605-2048x2048.jpeg 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/03\/AdobeStock_139809605-1150x1150.jpeg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/03\/AdobeStock_139809605-750x750.jpeg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/03\/AdobeStock_139809605-400x400.jpeg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/03\/AdobeStock_139809605-250x250.jpeg 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n\n<p>In this guide, we shall see how the internal RTC of STM32F4 is working and what features it holds and in part2, we shall configure the RTC and display the time and date on Liquid Crystal Display (LCD).<\/p>\n\n\n\n<p>In this guide, we will cover the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>What is RTC.<\/li><li>Feature of internal RTC.<\/li><li>Block diagram.<\/li><li>LCD connection.<\/li><li>Environment download.<\/li><\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1. What is RTC:<\/h2>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"what-does-real-time-clock-rtc-mean\">What Does Real-Time Clock (RTC) Mean?<\/h2>\n\n\n\n<p>A real-time clock (RTC) is a computer clock, usually in the form of an integrated circuit that is solely built for keeping time. Naturally, it counts hours, minutes, seconds, months, days and even years. RTCs can be found running in personal computers, embedded systems and servers, and are present in any electronic device that may require accurate time keeping. Being able to still function even when the computer is powered down through a battery or independently from the system\u2019s main power is fundamental.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"techopedia-explains-real-time-clock-rtc\">Explaining Real-Time Clock (RTC)<\/h2>\n\n\n\n<p>RTCs must accurately keep time, even when the device is powered off because, it is often used as a trigger for turning the device on or triggering events such as alarm clocks. RTC ICs run on an alternate power source, which allows it to continually operate under low power or even when the computer is turned off. ICs on older systems utilize lithium batteries, whereas newer systems make use of auxiliary batteries or supercapacitors. RTC ICs that use supercapacitors are rechargeable and can be soldered. But in most consumer-grade motherboards, the RTC is powered by a single battery that, when removed, resets the RTC to its starting point.<\/p>\n\n\n\n<p>RTC ICs regulate time with the use of a crystal oscillator and do not rely on clock signals like most hardware clocks. Aside from being responsible for the timing function of the system and its clock, RTC ICs ensure that all processes occurring in the system are appropriately synchronized. Although some may argue that this is a job for the system clock, the system clock is actually dependent on the RTC, making the RTC indirectly responsible for synchronization.<\/p>\n\n\n\n<p>An RTC battery should last for three to five years or more. RTCs are essential; if the battery fails, it must be replaced to ensure continued operation. A dead battery can be diagnosed with an error message at startup or if the user finds that the clock or the setup configuration has become corrupted, flaky or odd.<\/p>\n\n\n\n<p>Benefits of RTCs include:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>RTC ICs have proved to be more precise than other methods \u2014 like programming the timer of the controller.<\/li><li>It frees the main system from time-critical tasks.\u00a0<\/li><li>It has low power consumption and improved frequency stability.<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">2. Feature of Internal RTC:<\/h2>\n\n\n\n<p>The RTC unit main features are the following:<\/p>\n\n\n\n<p>\u2022 Calendar with subseconds, seconds, minutes, hours (12 or 24 format), day (day of week), date (day of month), month, and year.<\/p>\n\n\n\n<p>\u2022 Daylight saving compensation programmable by software.<\/p>\n\n\n\n<p>\u2022 Two programmable alarms with interrupt function. The alarms can be triggered by any combination of the calendar fields.<\/p>\n\n\n\n<p>\u2022 Automatic wakeup unit generating a periodic flag that triggers an automatic wakeup interrupt.<\/p>\n\n\n\n<p>\u2022 Reference clock detection: a more precise second source clock (50 or 60 Hz) can be used to enhance the calendar precision.<\/p>\n\n\n\n<p>\u2022 Accurate synchronization with an external clock using the subsecond shift feature.<\/p>\n\n\n\n<p>\u2022 Maskable interrupts\/events:<\/p>\n\n\n\n<p>\u2013 Alarm A<\/p>\n\n\n\n<p>\u2013 Alarm B<\/p>\n\n\n\n<p>\u2013 Wakeup interrupt<\/p>\n\n\n\n<p>\u2013 Timestamp<\/p>\n\n\n\n<p>\u2013 Tamper detection<\/p>\n\n\n\n<p>\u2022 Digital calibration circuit (periodic counter correction)<\/p>\n\n\n\n<p>\u2013 5 ppm accuracy<\/p>\n\n\n\n<p>\u2013 0.95 ppm accuracy, obtained in a calibration window of several seconds<\/p>\n\n\n\n<p>\u2022 Timestamp function for event saving (1 event)<\/p>\n\n\n\n<p>\u2022 Tamper detection:<\/p>\n\n\n\n<p>\u2013 Tamper event with configurable filter and internal pull-up.<\/p>\n\n\n\n<p>\u2022 20 backup registers (80 bytes). The backup registers are reset when a tamper detection event occurs.<\/p>\n\n\n\n<p>\u2022 Alternate function output (RTC_OUT) which selects one of the following two outputs:<\/p>\n\n\n\n<p>\u2013 RTC_CALIB: 512 Hz or 1 Hz clock output (with an LSE frequency of 32.768 kHz).<\/p>\n\n\n\n<p>This output is enabled by setting the COE bit in the RTC_CR register. It is routed to the device RTC_AF1 function.<\/p>\n\n\n\n<p>\u2013 RTC_ALARM (Alarm A, Alarm B or wakeup).<\/p>\n\n\n\n<p>This output is selected by configuring the OSEL[1:0] bits in the RTC_CR register. It is routed to the device RTC_AF1 function.<\/p>\n\n\n\n<p>\u2022 RTC additional function inputs:<\/p>\n\n\n\n<p>\u2013 RTC_TS: timestamp event detection. It is routed to the device RTC_AF1 function.<\/p>\n\n\n\n<p>\u2013 RTC_TAMP1: TAMPER1 event detection. It is routed to the device RTC_AF1 function.<\/p>\n\n\n\n<p>\u2013 RTC_REFIN: reference clock input (usually the mains, 50 or 60 Hz).<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">3. Block diagram:<\/h2>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"648\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/03\/Screenshot-2023-03-09-at-7.39.06-AM-1024x648.png\" alt=\"\" class=\"wp-image-1617\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/03\/Screenshot-2023-03-09-at-7.39.06-AM-1024x648.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/03\/Screenshot-2023-03-09-at-7.39.06-AM-300x190.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/03\/Screenshot-2023-03-09-at-7.39.06-AM-768x486.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/03\/Screenshot-2023-03-09-at-7.39.06-AM-1536x972.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/03\/Screenshot-2023-03-09-at-7.39.06-AM-2048x1296.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/03\/Screenshot-2023-03-09-at-7.39.06-AM-1150x728.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/03\/Screenshot-2023-03-09-at-7.39.06-AM-750x475.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/03\/Screenshot-2023-03-09-at-7.39.06-AM-400x253.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/03\/Screenshot-2023-03-09-at-7.39.06-AM-250x158.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">4. LCD Connection:<\/h2>\n\n\n\n<p>In this guide, we need the following part:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>LCD (16\u00d72 or 20\u00d74)<\/li><li>PCF8574 for LCD module<\/li><li>STM32F411RE Nucelo-64<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"568\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/12\/Screen-Shot-2021-12-27-at-6.22.13-AM-1024x568.png\" alt=\"\" class=\"wp-image-657\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/12\/Screen-Shot-2021-12-27-at-6.22.13-AM-1024x568.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/12\/Screen-Shot-2021-12-27-at-6.22.13-AM-300x166.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/12\/Screen-Shot-2021-12-27-at-6.22.13-AM-768x426.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/12\/Screen-Shot-2021-12-27-at-6.22.13-AM-1536x851.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/12\/Screen-Shot-2021-12-27-at-6.22.13-AM-2048x1135.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/12\/Screen-Shot-2021-12-27-at-6.22.13-AM-1150x637.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/12\/Screen-Shot-2021-12-27-at-6.22.13-AM-750x416.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/12\/Screen-Shot-2021-12-27-at-6.22.13-AM-400x222.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2021\/12\/Screen-Shot-2021-12-27-at-6.22.13-AM-250x139.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>No other components needed since the RTC is built-in.<\/p>\n\n\n\n<p>For more information, refer to <a href=\"https:\/\/blog.embeddedexpert.io\/?p=655\" data-type=\"URL\" data-id=\"https:\/\/blog.embeddedexpert.io\/?p=655\" target=\"_blank\" rel=\"noreferrer noopener\">this<\/a> guide.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">5. Environment download:<\/h2>\n\n\n\n<p>Since we will develop the code from scratch, you may download the code working environment from here:<\/p>\n\n\n\n<div class=\"wp-block-file\"><a href=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/03\/Internal_RTC.zip\">Internal_RTC<\/a><a href=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/03\/Internal_RTC.zip\" class=\"wp-block-file__button\" download>Download<\/a><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p>See you in next part.<\/p>\n\n\n\n<p>Happy coding \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this guide, we shall see how the internal RTC of STM32F4 is working and what features it holds and in part2, we shall configure the RTC and display the time and date on Liquid Crystal Display (LCD). In this guide, we will cover the following: What is RTC. Feature of internal RTC. Block diagram. [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,19,11,12],"tags":[],"class_list":["post-1615","post","type-post","status-publish","format-standard","hentry","category-embedded-systems","category-lcd","category-peripheral-drivers","category-stm32"],"_links":{"self":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/1615"}],"collection":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1615"}],"version-history":[{"count":1,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/1615\/revisions"}],"predecessor-version":[{"id":1619,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/1615\/revisions\/1619"}],"wp:attachment":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1615"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1615"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1615"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}