RTC subseconds
Posted: Tue May 19, 2020 1:29 pm
Hey everybody 
I'm using the STM32RTC.h lib on a Bluepill and would like to print data and timestamps into a .csv file.
I think rtc.getSubSeconds should give back milliseconds or am I wrong? I tried a small example and get back only zeros.
Does somebody know what I am doing wrong?
Result:

I'm using the STM32RTC.h lib on a Bluepill and would like to print data and timestamps into a .csv file.
I think rtc.getSubSeconds should give back milliseconds or am I wrong? I tried a small example and get back only zeros.
Does somebody know what I am doing wrong?
Code: Select all
#include "STM32RTC.h"
/* Get the rtc object */
STM32RTC& rtc = STM32RTC::getInstance();
/* Change these values to set the current initial time */
const byte seconds = 30;
const byte minutes = 28;
const byte hours = 15;
/* Change these values to set the current initial date */
/* Monday 15th June 2015 */
const byte weekDay = 2;
const byte day = 19;
const byte month = 5;
const byte year = 20;
void setup()
{
Serial.begin(9600);
// Select RTC clock source: LSI_CLOCK, LSE_CLOCK or HSE_CLOCK.
// By default the LSI is selected as source.
//rtc.setClockSource(STM32RTC::LSE_CLOCK);
rtc.begin(); // initialize RTC 24H format
// Set the time
rtc.setHours(hours);
rtc.setMinutes(minutes);
rtc.setSeconds(seconds);
// Set the date
rtc.setWeekDay(weekDay);
rtc.setDay(day);
rtc.setMonth(month);
rtc.setYear(year);
// you can use also
//rtc.setTime(hours, minutes, seconds);
//rtc.setDate(weekDay, day, month, year);
}
void loop()
{
// Print date...
print2digits(rtc.getDay());
Serial.print(".");
print2digits(rtc.getMonth());
Serial.print(".");
print2digits(rtc.getYear());
Serial.print(" ");
// ...and time
print2digits(rtc.getHours());
Serial.print(":");
print2digits(rtc.getMinutes());
Serial.print(":");
print2digits(rtc.getSeconds());
Serial.print(":");
print2digits(rtc.getSubSeconds());
Serial.println();
delay(100);
}
void print2digits(int number) {
if (number < 10) {
Serial.print("0"); // print a 0 before if the number is < than 10
}
Serial.print(number);
}
Result:
Code: Select all
19.05.20 15:28:35:00
19.05.20 15:28:35:00
19.05.20 15:28:35:00
19.05.20 15:28:35:00
19.05.20 15:28:35:00
19.05.20 15:28:35:00
19.05.20 15:28:35:00
19.05.20 15:28:35:00
19.05.20 15:28:35:00
19.05.20 15:28:36:00
19.05.20 15:28:36:00
19.05.20 15:28:36:00
19.05.20 15:28:36:00
19.05.20 15:28:36:00
19.05.20 15:28:36:00
19.05.20 15:28:36:00
19.05.20 15:28:36:00
19.05.20 15:28:36:00
19.05.20 15:28:36:00
19.05.20 15:28:36:00
19.05.20 15:28:37:00