Skip to content Skip to sidebar Skip to footer

STM32 RTC Internal Arduino Cara Akses Data RTC

STM32 Internal RTC Arduino

Arduino Internal STM32 RTC How to Access RTC Data - This article will give you how to Access STM32 RTC Data and display it to Arduino IDE Serial Monitor without reset.

This chip is now starting to be liked by Arduino programmers. How not, with the same chip size as the Atmega328, the Blue Pill STM32 chip board has several advantages over the Atmega328, one of which is Internal RTC.

A. STM32 RTC Internal

This is what I like the most, this chip is STM32F103C8T6 series which has Internal RTC, so it will simplify the circuit we will make, just add clock source, crystal oscillator.

Previously I had written a tutorial on how to access the Internal Pill Blue RTC STM32F103 data, and it worked. But when the power is cut off from the BLue Pill, the data stored correctly is the Hours, Minutes and Seconds data, while the Date, Month and Year will be reset to 1-1-2000. It's a bit annoying, it turns out that Date, Month and Year data is stored in SRAM.

Date data need to be saved to backup register in STM32F103C8T6 Blue Pill. Our friend from Gorontalo by the name "Zulns" has created an RTC library STM32F1 with data updates to the backup register. So even if power is cut off from STM32 or Blue Pill, Date, Month and Year will not be reset. Zulns, thanks for the library!

This article is an improvement article from the STM32F103 Bluepill Internal RTC article. How to manage and display RTC data on Arduino IDE Serial Monitor. The board I'm using is BluePill STM32F103. The library I'm using is Arduino_Core_STM32. You can download via this link, or click the button below.

B. ST Link V2 as Programmer STM32F103C8T6

To upload programs to stm32f103c8t6, I use ST Link V2 STM32 Programmer. Meanwhile, to see the results through the serial monitor on the Arduino IDE, I use FTDI.

Zulns has made excellent documentation of the STM32F1 RTC library on github, you can also read the download of the stm32f1_rtc.h library and the guide here.

C. Code Program

#include <stm32f1_rtc.h>
#define HIJRI_MODE_BIT 1
const char * weekdayName[] = { "Minggu", "Senin", "Selasa", "Rabu", "Kamis", "Jum'at", "Sabtu" };
const char * arabicWeekdayName[] = { "Ahad", "Ithnayn", "Thulatha", "Arba'a", "Khamis", "Jumu'ah", "Sabt" };
const char * monthName[] = { "Januari", "Februari", "Maret", "April", "Mei", "Juni", "Juli", "Augustus", "September", "Oktober", "November", "Desember" };
const char * hijriMonthName[] = { "Muharram", "Safar", "Rabi'al-Ula", "Rabi'ath-Thani", "Jumadal-Ula", "Jumadath-Thani", "Rajab", "Sha'ban", "Ramadan", "Shawwal", "Dhul-Qa'dah", "Dhul-Hijjah" };
DateVar date;
TimeVar time;
STM32F1_RTC rtc;
uint32_t epochTime;
bool isHijriMode = true;
void setup() {
isHijriMode = IS_HIJRI_MODE(rtc);
//Hilangkan komen baris dibawah jika ingin atur waktu
// setWaktu();
// delay(100);
epochTime = rtc.getTime();
rtc.epochToTime(epochTime, time);
void loop() {
if (rtc.isCounterUpdated()) {
epochTime = rtc.getTime();
rtc.epochToTime(epochTime, time);
printTime(); printDate(); }
void printTime() {
uint8_t h = time.hours;
Serial.print(" | ");
void print2Digits(uint8_t n) {
if (n < 10)
void setWaktu() {
// Tentukan waktu yang ingin di atur
time.hours = 11;
time.minutes = 35;
time.seconds = 0; = 15;
date.month = 5;
date.year = 2020;
epochTime = rtc.dateTimeToEpoch(date, time);
rtc.setTime(epochTime); }
void printDate() {
//Kalender Hijriah
rtc.epochToHijriDate(epochTime, date);
Serial.print(", ");
Serial.print(" ");
Serial.print(hijriMonthName[date.month - 1]);
Serial.print(" ");
Serial.print(" H");
Serial.print(" | ");
// Kalender Masehi
rtc.epochToDate(epochTime, date);
Serial.print(", ");
Serial.print(" ");
Serial.print(monthName[date.month - 1]);
Serial.print(" ");

Perbaiki Tanggal Reset Setelah Power di Matikan STM32F1 Blue Pill Internal RTC

If you think your RTC is counting seconds late, do not connect anything to pins PC14 and PC15.
If the header pin is still soldered to this pin, please remove it. This pin is connected directly to the RTC crystal.
This will interfere with the crystal oscillator oscillation. Notice in the picture below, I cut the PCB path on the PC14 and PC15 pins. And now it runs normally.
STM32 RTC Internal Arduino Cara Akses Data RTC

I hope this can help you in developing an STM32 RTC based electronic device that requires RTC. Just that.

2 comments for "STM32 RTC Internal Arduino Cara Akses Data RTC"

  1. terima kasih atas tutorial yg sangat membantu, izin bertanya bagaimana cara menyesuaikan waktu rtc dengan waktu sekarang? saya sudah membaca dokumtasi githubnya namun belum paham cara setting waktunya

    mohon bantuannya, terima kasih!

    1. Uncomment baris // setWaktu();

      terus, ubah waktu di void setWaktu() {
      time.hours = 11;
      time.minutes = 35;
      time.seconds = 0; = 15;
      date.month = 5;
      date.year = 2020;

      sesuaikan dengan waktu sekarang. Lalu upload.

      Setelah itu comment lagi setWaktu(); , lalu upload lagi biar waktu tidak diseting berulang.

      Semoga membantu.