RTC subseconds

Post here first, or if you can't find a relevant section!
Post Reply
jenspogo
Posts: 30
Joined: Mon Feb 24, 2020 10:42 am

RTC subseconds

Post by jenspogo »

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?

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
User avatar
fpiSTM
Posts: 1723
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: RTC subseconds

Post by fpiSTM »

There is no issue.
STM32F1 does not support subseconds as it is not available like on other STM32 series.
jenspogo
Posts: 30
Joined: Mon Feb 24, 2020 10:42 am

Re: RTC subseconds

Post by jenspogo »

ok, thanks!
Are there any Ideas how to build a workaround? maybe with the millis(); function?
User avatar
fpiSTM
Posts: 1723
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: RTC subseconds

Post by fpiSTM »

Well no idea.
I guess using millis() will not be precise due to the time needed for computation?
jenspogo
Posts: 30
Joined: Mon Feb 24, 2020 10:42 am

Re: RTC subseconds

Post by jenspogo »

Might be true.
I thought about a combination of the RTC and a Millie Counter only between the logging calls.
I will try it out and if the results are more or less acceptable, I will show it here.
Post Reply

Return to “General discussion”