{"id":4303,"date":"2019-09-18T20:00:10","date_gmt":"2019-09-18T18:00:10","guid":{"rendered":"https:\/\/msalamon.pl\/?p=4303"},"modified":"2025-12-27T19:22:19","modified_gmt":"2025-12-27T18:22:19","slug":"further-struggles-with-rtc-ds1307-and-pcf8563-on-stm32","status":"publish","type":"post","link":"https:\/\/msalamon.pl\/en\/further-struggles-with-rtc-ds1307-and-pcf8563-on-stm32\/","title":{"rendered":"Further struggles with RTC \u2013 DS1307 and PCF8563 on STM32"},"content":{"rendered":"\n<p>Recently I focused my attention on the insanely accurate RTC <a href=\"http:\/\/msalamon.pl\/piekielnie-dokladny-rtc-ds3231-na-stm32\/\">DS3231<\/a>. It does not require an external crystal and additionally has built-in temperature compensation. However, there are plenty of other real-time clocks on the market. They don\u2019t necessarily boast about being accurate. Let\u2019s take a closer look at what they offer and how to deal with them.<\/p>\n\n\n\n<!--more-->\n\n\n\n<h1 class=\"wp-block-heading\">DS1307<\/h1>\n\n\n\n<p class=\"has-text-align-left\"><a href=\"https:\/\/sklep.msalamon.pl\/produkt\/modul-ds1307-rtc-24c32-eeprom-z-gniazdem-na-baterie\/?utm_source=blog&amp;utm_medium=article&amp;utm_campaign=other_rtc&amp;utm_content=Text\">DS1307<\/a> is one of the most popular RTCs. It\u2019s usually the first one that pops up in search engines. It has also been described in every possible way. There are plenty of ready-made modules with this chip. You can buy one of these modules in my store.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><a href=\"https:\/\/sklep.msalamon.pl\/produkt\/modul-ds1307-rtc-24c32-eeprom-z-gniazdem-na-baterie\/?utm_source=blog&amp;utm_medium=banner&amp;utm_campaign=other_rtc&amp;utm_content=ds1307\"><img loading=\"lazy\" decoding=\"async\" width=\"1200\" height=\"400\" src=\"http:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/DS1307_baner.jpg\" alt=\"\" class=\"wp-image-1189\" srcset=\"https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/DS1307_baner.jpg 1200w, https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/DS1307_baner-300x100.jpg 300w, https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/DS1307_baner-1024x341.jpg 1024w, https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/DS1307_baner-768x256.jpg 768w, https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/DS1307_baner-24x8.jpg 24w, https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/DS1307_baner-36x12.jpg 36w, https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/DS1307_baner-160x53.jpg 160w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/a><\/figure>\n<\/div>\n\n\n<p><\/p>\n\n\n\n<p class=\"has-text-align-left\">Its success undoubtedly lies in its price. It\u2019s an insanely cheap chip. Even though it requires a few additional external components, it\u2019s still financially worth it.<\/p>\n\n\n\n<p>Additionally, using the <a href=\"https:\/\/sklep.msalamon.pl\/produkt\/modul-ds1307-rtc-24c32-eeprom-z-gniazdem-na-baterie\/?utm_source=blog&amp;utm_medium=article&amp;utm_campaign=other_rtc&amp;utm_content=Text\">DS1307<\/a> is very simple, as I\u2019ll show in a moment.<\/p>\n\n\n\n<p class=\"has-text-align-left\">First, I wanted to show you how it differs from the <a href=\"http:\/\/msalamon.pl\/piekielnie-dokladny-rtc-ds3231-na-stm32\/\">DS3231 from the previous post<\/a>. The first thing that stands out is the supply voltage. Unfortunately, the <a href=\"https:\/\/sklep.msalamon.pl\/produkt\/modul-ds1307-rtc-24c32-eeprom-z-gniazdem-na-baterie\/?utm_source=blog&amp;utm_medium=article&amp;utm_campaign=other_rtc&amp;utm_content=Text\">DS1307<\/a> only tolerates around 5 V. If you want to use it with an STM32, you need two voltages (fortunately, both are available on Nucleo). Luckily, the STM32 tolerates 5 V on its inputs, so there\u2019s nothing to worry about on that side. I2C is, fortunately, open-drain, so there is no problem translating 3.3 -&gt; 5 V for the DS1307.<\/p>\n\n\n\n<p class=\"has-text-align-left\">Another limitation compared to the accurate <a href=\"https:\/\/sklep.msalamon.pl\/produkt\/modul-ds3231-rtc-24c32-eeprom-z-gniazdem-na-baterie\/?utm_source=blog&amp;utm_medium=article&amp;utm_campaign=other_rtc&amp;utm_content=Text\">DS3231<\/a> is the I\u00b2C interface speed. With the <a href=\"https:\/\/sklep.msalamon.pl\/produkt\/modul-ds1307-rtc-24c32-eeprom-z-gniazdem-na-baterie\/?utm_source=blog&amp;utm_medium=article&amp;utm_campaign=other_rtc&amp;utm_content=Text\">DS1307<\/a> you\u2019ll get guaranteed stability only up to a 100 kHz clock. Sad face \ud83d\ude41<\/p>\n\n\n\n<p class=\"has-text-align-left\">There\u2019s also no way to change the I\u00b2C address. There\u2019s one fixed address. Exactly the same as on the <a href=\"https:\/\/sklep.msalamon.pl\/produkt\/modul-ds3231-rtc-24c32-eeprom-z-gniazdem-na-baterie\/?utm_source=blog&amp;utm_medium=article&amp;utm_campaign=other_rtc&amp;utm_content=Text\">DS3231<\/a>.<\/p>\n\n\n\n<p class=\"has-text-align-left\">It also lacks an alarm function, but I\u2019m not crying over that. I\u2019ve never used it. Maybe one day I\u2019ll finally need it.<\/p>\n\n\n\n<p class=\"has-text-align-left\">Alright, but is there anything positive? There is \ud83d\ude42 The <a href=\"https:\/\/sklep.msalamon.pl\/produkt\/modul-ds1307-rtc-24c32-eeprom-z-gniazdem-na-baterie\/?utm_source=blog&amp;utm_medium=article&amp;utm_campaign=other_rtc&amp;utm_content=Text\">DS1307<\/a> has 56 bytes of battery-backed RAM. A very cool feature when you need to store some data while putting the microcontroller into the deepest power-saving modes.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Connecting and programming the DS1307<\/h3>\n\n\n\n<p class=\"has-text-align-left\">Today, just like with the <a href=\"https:\/\/sklep.msalamon.pl\/produkt\/modul-ds3231-rtc-24c32-eeprom-z-gniazdem-na-baterie\/?utm_source=blog&amp;utm_medium=article&amp;utm_campaign=other_rtc&amp;utm_content=Text\">DS3231<\/a>, I used the Nucleo F410RB. The wiring is completely simple, just like in the previous post.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><a href=\"http:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/ds1307_schematic.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"300\" height=\"179\" src=\"http:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/ds1307_schematic-300x179.jpg\" alt=\"\" class=\"wp-image-1168\" srcset=\"https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/ds1307_schematic-300x179.jpg 300w, https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/ds1307_schematic-1024x611.jpg 1024w, https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/ds1307_schematic-768x458.jpg 768w, https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/ds1307_schematic-24x14.jpg 24w, https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/ds1307_schematic-36x21.jpg 36w, https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/ds1307_schematic-134x80.jpg 134w, https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/ds1307_schematic.jpg 1090w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/figure>\n<\/div>\n\n\n<p><\/p>\n\n\n\n<p class=\"has-text-align-left\">For the software I used STM32CubeIDE version 1.0.2 and the HAL F4 library version 1.24.1.<\/p>\n\n\n\n<p class=\"has-text-align-left\">Exactly like in the previous post, I wrote non-blocking handling via DMA. The code is surprisingly similar, because the registers holding the date and time in almost every RTC look the same or similar. I\u2019m curious about the I\u00b2C transfer times.<\/p>\n\n\n\n<p class=\"has-text-align-left\">I\u2019ll skip the Cube configuration because it is the same as for the <a href=\"https:\/\/sklep.msalamon.pl\/produkt\/modul-ds3231-rtc-24c32-eeprom-z-gniazdem-na-baterie\/?utm_source=blog&amp;utm_medium=article&amp;utm_campaign=other_rtc&amp;utm_content=Text\">DS3231<\/a> \u2014 I\u00b2C with DMA, an EXTI interrupt on a single edge, and UART for printing to the terminal.<\/p>\n\n\n\n<p class=\"has-text-align-left\">Remember, however, that the DS1307 tolerates a maximum of 100 kHz on the I\u00b2C clock, so set it accordingly.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">DS1307 code<\/h3>\n\n\n\n<p class=\"has-text-align-left\">I\u2019d like to focus only on the differences compared to the <a href=\"https:\/\/sklep.msalamon.pl\/produkt\/modul-ds3231-rtc-24c32-eeprom-z-gniazdem-na-baterie\/?utm_source=blog&amp;utm_medium=article&amp;utm_campaign=other_rtc&amp;utm_content=Text\">DS3231<\/a>. During initialization, it is required to enable the clock driving the chip, because after connecting power the RTC will not start counting on its own. It\u2019s an interesting method of a controlled clock start. You can also nicely use this to count working hours in a device. Additionally, I set the SQW pin to a 1 Hz square wave so that the interrupt works as expected.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"c\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">void DS1307_Init(I2C_HandleTypeDef *hi2c)\n{\n\thi2c_ds1307 = hi2c;\n\n\tDS1307_SQWRateSelect(SQW_RATE_1HZ);\n\tDS1307_SQWEnable(1);\n\tDS1307_ClockHalt(0);\n}<\/pre>\n\n\n\n<p class=\"has-text-align-left\">You must remember to override the callback functions for DMA as well as the EXTI interrupt. You can do this in the fourth user code section in the main.c file.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"c\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)\n{\n\tif(GPIO_Pin == DS1307_INT_Pin)\n\t{\n\t\tDS1307_ReceiveDateTimeDMA();\n\t}\n}\n\nvoid HAL_I2C_MemRxCpltCallback(I2C_HandleTypeDef *hi2c)\n{\n\tDS1307_CalculateDateTime(&amp;amp;r);\n}<\/pre>\n\n\n\n<p class=\"has-text-align-left\">And that\u2019s it for handling the library. Simple and pleasant as always \ud83d\ude42<\/p>\n\n\n\n<p class=\"has-text-align-left\">An addition I mentioned earlier is the battery-backed RAM. I wrote simple functions to write to this memory.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"c\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">void DS1307_ReadRAM(uint8_t Address, uint8_t *Value, uint8_t Length);\nvoid DS1307_WriteRAM(uint8_t Address, uint8_t *Value, uint8_t Length);<\/pre>\n\n\n\n<p>The RAM address range you can use is 0x08 \u00f7 0x3F.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">DS1307 performance<\/h3>\n\n\n\n<p class=\"has-text-align-left\">Let\u2019s check how it behaves both in a blocking interrupt and via DMA.<\/p>\n\n\n\n<p>100 kHz interrupt<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><a href=\"http:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/ds1307_interrupt_100k.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"138\" src=\"http:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/ds1307_interrupt_100k-1024x138.jpg\" alt=\"\" class=\"wp-image-1170\" srcset=\"https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/ds1307_interrupt_100k-1024x138.jpg 1024w, https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/ds1307_interrupt_100k-300x40.jpg 300w, https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/ds1307_interrupt_100k-768x104.jpg 768w, https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/ds1307_interrupt_100k-1536x207.jpg 1536w, https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/ds1307_interrupt_100k-24x3.jpg 24w, https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/ds1307_interrupt_100k-36x5.jpg 36w, https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/ds1307_interrupt_100k-160x22.jpg 160w, https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/ds1307_interrupt_100k.jpg 1920w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n<\/div>\n\n\n<p><\/p>\n\n\n\n<p>100 kHz DMA<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><a href=\"http:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/ds1307_DMA_100k.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"161\" src=\"http:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/ds1307_DMA_100k-1024x161.jpg\" alt=\"\" class=\"wp-image-1169\" srcset=\"https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/ds1307_DMA_100k-1024x161.jpg 1024w, https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/ds1307_DMA_100k-300x47.jpg 300w, https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/ds1307_DMA_100k-768x120.jpg 768w, https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/ds1307_DMA_100k-1536x241.jpg 1536w, https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/ds1307_DMA_100k-24x4.jpg 24w, https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/ds1307_DMA_100k-36x6.jpg 36w, https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/ds1307_DMA_100k-160x25.jpg 160w, https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/ds1307_DMA_100k.jpg 1920w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n<\/div>\n\n\n<p><\/p>\n\n\n\n<p>The handling time is 916 \u00b5s in the interrupt vs 301 \u00b5s with DMA.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">PCF8563<\/h2>\n\n\n\n<p class=\"has-text-align-left\">Another popular chip is the <a href=\"https:\/\/sklep.msalamon.pl\/produkt\/modul-pcf8563-rtc-z-gniazdem-na-baterie\/?utm_source=blog&amp;utm_medium=article&amp;utm_campaign=other_rtc&amp;utm_content=Text\">PCF8563<\/a>. There are modules for it as well, which you can buy in my store.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><a href=\"https:\/\/sklep.msalamon.pl\/produkt\/modul-pcf8563-rtc-z-gniazdem-na-baterie\/?utm_source=blog&amp;utm_medium=banner&amp;utm_campaign=other_rtc&amp;utm_content=pcf8563\"><img loading=\"lazy\" decoding=\"async\" width=\"1200\" height=\"400\" src=\"http:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/PCF8563_baner.jpg\" alt=\"\" class=\"wp-image-1188\" srcset=\"https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/PCF8563_baner.jpg 1200w, https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/PCF8563_baner-300x100.jpg 300w, https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/PCF8563_baner-1024x341.jpg 1024w, https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/PCF8563_baner-768x256.jpg 768w, https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/PCF8563_baner-24x8.jpg 24w, https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/PCF8563_baner-36x12.jpg 36w, https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/PCF8563_baner-160x53.jpg 160w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/a><\/figure>\n<\/div>\n\n\n<p><\/p>\n\n\n\n<p class=\"has-text-align-left\">What makes this chip stand out? It can be powered incredibly low. For proper I\u00b2C communication, 1.8 V is enough. This value allows you to use this RTC in circuits aimed at extremely low power consumption.<\/p>\n\n\n\n<p class=\"has-text-align-left\">Additionally, the chip happily accepts 400 kHz on the I\u00b2C clock.<\/p>\n\n\n\n<p class=\"has-text-align-left\">The module has an alarm function and an interesting 8-bit countdown Timer feature. After counting down, it can assert an interrupt. A cool gadget for those who are short on timers in the microcontroller.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Connecting and programming the PCF8563<\/h3>\n\n\n\n<p>The connection is analogous to the above.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><a href=\"http:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/pcf8563_schematic.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"300\" height=\"175\" src=\"http:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/pcf8563_schematic-300x175.jpg\" alt=\"\" class=\"wp-image-1171\" srcset=\"https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/pcf8563_schematic-300x175.jpg 300w, https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/pcf8563_schematic-1024x597.jpg 1024w, https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/pcf8563_schematic-768x448.jpg 768w, https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/pcf8563_schematic-24x14.jpg 24w, https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/pcf8563_schematic-36x21.jpg 36w, https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/pcf8563_schematic-137x80.jpg 137w, https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/pcf8563_schematic.jpg 1318w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/figure>\n<\/div>\n\n\n<p><\/p>\n\n\n\n<p class=\"has-text-align-left\">Cube configuration? No changes \ud83d\ude42 Okay, there will be one. The <a href=\"https:\/\/sklep.msalamon.pl\/produkt\/modul-pcf8563-rtc-z-gniazdem-na-baterie\/?utm_source=blog&amp;utm_medium=article&amp;utm_campaign=other_rtc&amp;utm_content=Text\">PCF8563<\/a> allows operation at 400 kHz on the I\u00b2C clock line, so use that if you\u2019re at 100 kHz.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">PCF8563 code<\/h3>\n\n\n\n<p class=\"has-text-align-left\">Quite possibly you\u2019ve already guessed what it will look like. Of course, it\u2019s similar to the previous code. I did not implement the alarm and built-in Timer. If you feel like it, I\u2019ll be happy if you contribute to <a href=\"https:\/\/github.com\/lamik\" target=\"_blank\" rel=\"noopener\">my repository<\/a>.<\/p>\n\n\n\n<p class=\"has-text-align-left\">From a user perspective, it is of course enough to initialize the RTC and read data in the interrupt or via DMA. During initialization, I set the 1 Hz output signal from the chip and, although the clock starts by default after applying power, I clear the STOP bit to be sure.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"c\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">void PCF8563_Init(I2C_HandleTypeDef *hi2c)\n{\n  hi2c_pcf8563 = hi2c;\n\n  PCF8563_ClkoutFrequency(CLKOUT_FREQ_1HZ);\n  PCF8563_STOPEnable(0);\n}<\/pre>\n\n\n\n<p class=\"has-text-align-left\">DMA receive handling is analogous to the previous examples. The entire handling is contained in the fourth USER CODE section.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"c\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)\n{\n  if(GPIO_Pin == PCF8563_INT_Pin)\n  {\n    PCF8563_ReceiveDateTimeDMA();\n  }\n}\n\nvoid HAL_I2C_MemRxCpltCallback(I2C_HandleTypeDef *hi2c)\n{\n  PCF8563_CalculateDateTime(&amp;amp;r);\n}<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">PCF8563 performance<\/h3>\n\n\n\n<p>Let\u2019s look at the waveforms for reading in a blocking interrupt and via DMA.<\/p>\n\n\n\n<p>100 kHz interrupt<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><a href=\"http:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/pcf8563_interrupt_100k.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"166\" src=\"http:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/pcf8563_interrupt_100k-1024x166.jpg\" alt=\"\" class=\"wp-image-1172\" srcset=\"https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/pcf8563_interrupt_100k-1024x166.jpg 1024w, https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/pcf8563_interrupt_100k-300x49.jpg 300w, https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/pcf8563_interrupt_100k-768x124.jpg 768w, https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/pcf8563_interrupt_100k-1536x249.jpg 1536w, https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/pcf8563_interrupt_100k-24x4.jpg 24w, https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/pcf8563_interrupt_100k-36x6.jpg 36w, https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/pcf8563_interrupt_100k-160x26.jpg 160w, https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/pcf8563_interrupt_100k.jpg 1680w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n<\/div>\n\n\n<p><\/p>\n\n\n\n<p>400 kHz interrupt<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><a href=\"http:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/pcf8563_interrupt_400k.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"161\" src=\"http:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/pcf8563_interrupt_400k-1024x161.jpg\" alt=\"\" class=\"wp-image-1173\" srcset=\"https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/pcf8563_interrupt_400k-1024x161.jpg 1024w, https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/pcf8563_interrupt_400k-300x47.jpg 300w, https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/pcf8563_interrupt_400k-768x121.jpg 768w, https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/pcf8563_interrupt_400k-1536x241.jpg 1536w, https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/pcf8563_interrupt_400k-24x4.jpg 24w, https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/pcf8563_interrupt_400k-36x6.jpg 36w, https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/pcf8563_interrupt_400k-160x25.jpg 160w, https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/pcf8563_interrupt_400k.jpg 1680w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n<\/div>\n\n\n<p><\/p>\n\n\n\n<p>100 kHz DMA<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><a href=\"http:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/pcf8563_DMA_100k.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"178\" src=\"http:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/pcf8563_DMA_100k-1024x178.jpg\" alt=\"\" class=\"wp-image-1174\" srcset=\"https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/pcf8563_DMA_100k-1024x178.jpg 1024w, https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/pcf8563_DMA_100k-300x52.jpg 300w, https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/pcf8563_DMA_100k-768x133.jpg 768w, https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/pcf8563_DMA_100k-1536x266.jpg 1536w, https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/pcf8563_DMA_100k-24x4.jpg 24w, https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/pcf8563_DMA_100k-36x6.jpg 36w, https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/pcf8563_DMA_100k-160x28.jpg 160w, https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/pcf8563_DMA_100k.jpg 1678w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n<\/div>\n\n\n<p><\/p>\n\n\n\n<p>400 kHz DMA<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><a href=\"http:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/pcf8563_DMA_400k.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"178\" src=\"http:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/pcf8563_DMA_400k-1024x178.jpg\" alt=\"\" class=\"wp-image-1175\" srcset=\"https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/pcf8563_DMA_400k-1024x178.jpg 1024w, https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/pcf8563_DMA_400k-300x52.jpg 300w, https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/pcf8563_DMA_400k-768x133.jpg 768w, https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/pcf8563_DMA_400k-1536x267.jpg 1536w, https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/pcf8563_DMA_400k-24x4.jpg 24w, https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/pcf8563_DMA_400k-36x6.jpg 36w, https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/pcf8563_DMA_400k-160x28.jpg 160w, https:\/\/msalamon.pl\/wp-content\/uploads\/2019\/09\/pcf8563_DMA_400k.jpg 1680w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n<\/div>\n\n\n<p><\/p>\n\n\n\n<p>I\u2019ll now compare these results with those obtained for the DS3231 and DS1307.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Comparison of various RTCs<\/h2>\n\n\n\n<p>I gathered all the results in a table.<\/p>\n\n\n\n<figure class=\"wp-block-table tablepress tablepress-id-14\"><table class=\"has-fixed-layout\"><thead><tr><td><\/td><th>DS3231<\/th><th>DS1307<\/th><th>PCF8563<\/th><\/tr><\/thead><tbody><tr><td>100 kHz INT<\/td><td>919 \u00b5s<\/td><td>916 \u00b5s<\/td><td>924 \u00b5s<\/td><\/tr><tr><td>400 kHz INT<\/td><td>237 \u00b5s<\/td><td>X<\/td><td>308 \u00b5s<\/td><\/tr><tr><td>100 kHz DMA<\/td><td>301\u00b5s<\/td><td>301 \u00b5s<\/td><td>302 \u00b5s<\/td><\/tr><tr><td>400 kHz DMA<\/td><td>85 \u00b5s<\/td><td>X<\/td><td>107 \u00b5s<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"has-text-align-left\">As you can see, the results between the individual chips are close to each other. I\u2019m wondering about the 400 kHz DMA time. Why is there a visible difference of about 20 \u00b5s when issuing the DMA transfer? The SysTick interrupt has the same priority, so I exclude interference from it. Perhaps the analyzer introduced some error. Nonetheless, the results are comparable.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><figure><a href=\"https:\/\/sklep.msalamon.pl\/kategoria-produktu\/dev-boardy\/stm32-nucleo\/?utm_source=blog&amp;utm_medium=banner&amp;utm_campaign=other_rtc&amp;utm_content=nucleo\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/msalamon.pl\/wp-content\/uploads\/2020\/07\/Nucleo-64-baner.jpg\" alt=\"\" width=\"1200\" height=\"400\" class=\"aligncenter wp-image-1593 size-full\" srcset=\"https:\/\/msalamon.pl\/wp-content\/uploads\/2020\/07\/Nucleo-64-baner.jpg 1200w, https:\/\/msalamon.pl\/wp-content\/uploads\/2020\/07\/Nucleo-64-baner-300x100.jpg 300w, https:\/\/msalamon.pl\/wp-content\/uploads\/2020\/07\/Nucleo-64-baner-1024x341.jpg 1024w, https:\/\/msalamon.pl\/wp-content\/uploads\/2020\/07\/Nucleo-64-baner-768x256.jpg 768w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\"><\/a><\/figure><\/h1>\n\n\n\n<h2 class=\"wp-block-heading\">Summary<\/h2>\n\n\n\n<p class=\"has-text-align-left\">I checked two other popular RTCs that you can use in your projects \u2014 <a href=\"https:\/\/sklep.msalamon.pl\/produkt\/modul-ds1307-rtc-24c32-eeprom-z-gniazdem-na-baterie\/?utm_source=blog&amp;utm_medium=article&amp;utm_campaign=other_rtc&amp;utm_content=Text\">DS1307<\/a> and <a href=\"https:\/\/sklep.msalamon.pl\/produkt\/modul-pcf8563-rtc-z-gniazdem-na-baterie\/?utm_source=blog&amp;utm_medium=article&amp;utm_campaign=other_rtc&amp;utm_content=Text\">PCF8563<\/a>. Both in theory are not paragons of accuracy, which I have not yet tested experimentally. Maybe I\u2019ll do such a test soon \ud83d\ude42<\/p>\n\n\n\n<p class=\"has-text-align-left\">It\u2019s worth using faster I\u00b2C transmission and DMA communication. You can save a lot of valuable time. I\u2019ve encountered a small complaint that some DMA channel is always occupied. That\u2019s what it\u2019s for \u2014 to use it. Unless it\u2019s needed for more important things. Then you can do another trick.<\/p>\n\n\n\n<p class=\"has-text-align-left\">STM32 has a built-in RTC. It does have a lousy RC oscillator with an error of a few percent, but it can be clocked by an external oscillator. Thanks to this you\u2019ll offload the DMA. That\u2019s also worth checking.<\/p>\n\n\n\n<p class=\"has-text-align-left\">The full project along with the library can be found, as usual, on my GitHub: <a href=\"https:\/\/github.com\/lamik\/DS1307_RTC_STM32_HAL\" target=\"_blank\" rel=\"noopener\">DS1307<\/a>, <a href=\"https:\/\/github.com\/lamik\/PCF8563_RTC_STM32_HAL\" target=\"_blank\" rel=\"noopener\">PCF8563<\/a><\/p>\n\n\n\n<p class=\"has-text-align-left\"><span>If you noticed an error, disagree with something, would like to add something important, or simply feel like discussing the topic, write a comment. Remember that the discussion should be polite and in line with the rules of the Polish language.<\/span><\/p>\n\n\n<div class=\"kk-star-ratings kksr-auto kksr-align-left kksr-valign-bottom\"\n    data-payload='{&quot;align&quot;:&quot;left&quot;,&quot;id&quot;:&quot;4303&quot;,&quot;slug&quot;:&quot;default&quot;,&quot;valign&quot;:&quot;bottom&quot;,&quot;ignore&quot;:&quot;&quot;,&quot;reference&quot;:&quot;auto&quot;,&quot;class&quot;:&quot;&quot;,&quot;count&quot;:&quot;0&quot;,&quot;legendonly&quot;:&quot;&quot;,&quot;readonly&quot;:&quot;&quot;,&quot;score&quot;:&quot;0&quot;,&quot;starsonly&quot;:&quot;&quot;,&quot;best&quot;:&quot;5&quot;,&quot;gap&quot;:&quot;0&quot;,&quot;greet&quot;:&quot;&quot;,&quot;legend&quot;:&quot;0\\\/5 - (0 votes)&quot;,&quot;size&quot;:&quot;24&quot;,&quot;title&quot;:&quot;Further struggles with RTC \u2013 DS1307 and PCF8563 on STM32&quot;,&quot;width&quot;:&quot;0&quot;,&quot;_legend&quot;:&quot;{score}\\\/{best} - ({count} {votes})&quot;,&quot;font_factor&quot;:&quot;1.25&quot;}'>\n            \n<div class=\"kksr-stars\">\n    \n<div class=\"kksr-stars-inactive\">\n            <div class=\"kksr-star\" data-star=\"1\" style=\"padding-right: 0px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"2\" style=\"padding-right: 0px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"3\" style=\"padding-right: 0px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"4\" style=\"padding-right: 0px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" data-star=\"5\" style=\"padding-right: 0px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n    <\/div>\n    \n<div class=\"kksr-stars-active\" style=\"width: 0px;\">\n            <div class=\"kksr-star\" style=\"padding-right: 0px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 0px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 0px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 0px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n            <div class=\"kksr-star\" style=\"padding-right: 0px\">\n            \n\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n        <\/div>\n    <\/div>\n<\/div>\n                \n\n<div class=\"kksr-legend\" style=\"font-size: 19.2px;\">\n            <span class=\"kksr-muted\"><\/span>\n    <\/div>\n    <\/div>\n","protected":false},"excerpt":{"rendered":"<p>Recently I focused my attention on the insanely accurate RTC DS3231. It does not require an external crystal and additionally has built-in temperature compensation. However, there are plenty of other real-time clocks on the market. They don\u2019t necessarily boast about being accurate. Let\u2019s take a closer look at what they [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3300,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_links_to":"","_links_to_target":""},"categories":[160],"tags":[175,176,174,177],"class_list":["post-4303","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-stm32","tag-electronics","tag-programming","tag-stm32","tag-stm32cubemx"],"_links":{"self":[{"href":"https:\/\/msalamon.pl\/en\/wp-json\/wp\/v2\/posts\/4303","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/msalamon.pl\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/msalamon.pl\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/msalamon.pl\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/msalamon.pl\/en\/wp-json\/wp\/v2\/comments?post=4303"}],"version-history":[{"count":3,"href":"https:\/\/msalamon.pl\/en\/wp-json\/wp\/v2\/posts\/4303\/revisions"}],"predecessor-version":[{"id":4411,"href":"https:\/\/msalamon.pl\/en\/wp-json\/wp\/v2\/posts\/4303\/revisions\/4411"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/msalamon.pl\/en\/wp-json\/wp\/v2\/media\/3300"}],"wp:attachment":[{"href":"https:\/\/msalamon.pl\/en\/wp-json\/wp\/v2\/media?parent=4303"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/msalamon.pl\/en\/wp-json\/wp\/v2\/categories?post=4303"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/msalamon.pl\/en\/wp-json\/wp\/v2\/tags?post=4303"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}