A ds3231 library for the STM32 Blue Pill

Development environment specific, Arduino, Eclipse, VS2013, Em::Blocks etc
ChPr
Posts: 20
Joined: Thu Jun 20, 2024 8:03 am
Answers: 1

A ds3231 library for the STM32 Blue Pill

Post by ChPr »

Hello everybody,

I have a DS3231 library that works well with Arduino such as: Pro Mini, ... Mega 2560. But this library doesn't work with the STM32 Blue Pill.

Do you know of a DS3231 library compatible with the STM32 Blue Pill ?

Sincerely.

Pierre.
by ChPr » Sun Jun 23, 2024 1:16 pm
Seeing a lot of libraries for the DS3231, I posted here to find out which one to choose.

I kept searching the web and found this https://how2electronics.com/stm32-ds323 ... lock-oled/ which described exactly what I wanted to do (DS3231 and OLED).

My problem is now solved.

Thank you for your attention.

Sincerely.

Yours sincerely
Go to full post
ChPr
Posts: 20
Joined: Thu Jun 20, 2024 8:03 am
Answers: 1

Re: A ds3231 library for the STM32 Blue Pill

Post by ChPr »

Seeing a lot of libraries for the DS3231, I posted here to find out which one to choose.

I kept searching the web and found this https://how2electronics.com/stm32-ds323 ... lock-oled/ which described exactly what I wanted to do (DS3231 and OLED).

My problem is now solved.

Thank you for your attention.

Sincerely.

Yours sincerely
STM32ardui
Posts: 105
Joined: Mon May 06, 2024 1:46 pm
Answers: 1
Location: Germany

Re: A ds3231 library for the STM32 Blue Pill

Post by STM32ardui »

Why do you use a DS3231-module?

A STM32F103 has an internal RTC and on BluePill-boards should be a VBAT-pin, where you can connect a coin cell or a supercap. Application note AN2604 describes how to calibrate the RTC.
{chapter 2.3.9, 2.3.14 and figure 14 "Power supply scheme" in datasheet]
GonzoG
Posts: 426
Joined: Wed Jan 15, 2020 11:30 am
Answers: 30
Location: Prudnik, Poland

Re: A ds3231 library for the STM32 Blue Pill

Post by GonzoG »

STM32ardui wrote: Tue Jun 25, 2024 6:05 am Why do you use a DS3231-module?

A STM32F103 has an internal RTC and on BluePill-boards should be a VBAT-pin, where you can connect a coin cell or a supercap. Application note AN2604 describes how to calibrate the RTC.
{chapter 2.3.9, 2.3.14 and figure 14 "Power supply scheme" in datasheet]
Probably same reason many boards with MCUs use external oscillators - precision.
I couldn't get the built in RTC to be precise. Even after calibration (with precise frequency meter) it was few seconds/week off, but once it was +5s, other week it was -10s. The best outcome was 30s/month.

Where with DS3231 I've got 1s/month after a week of calibration without any tools, just comparing time.
ag123
Posts: 1748
Joined: Thu Dec 19, 2019 5:30 am
Answers: 27

Re: A ds3231 library for the STM32 Blue Pill

Post by ag123 »

stm32's rtc is quite stable / precise with a decent 32k LSI crystal.
But that once, I bought *cheap* crystals
https://www.aliexpress.com/w/wholesale-32768.html
that has a drift
that gets solved by using drift correction
https://github.com/rogerclarkmelbourne/ ... /RTCAdjust
in practical terms that works, reducing the monthly (or even over several months) variation to a minute or less.
I didn't bother to check once in that state, instead I manually synced the RTC every month or so
the benefit here is the reduced discrete part count, it becomes just a crystal and maybe caps.
STM32ardui
Posts: 105
Joined: Mon May 06, 2024 1:46 pm
Answers: 1
Location: Germany

Re: A ds3231 library for the STM32 Blue Pill

Post by STM32ardui »

ag123 wrote: Tue Jun 25, 2024 11:02 am stm32's rtc is quite stable / precise with a decent 32k LSI crystal.
?
LSE ?
GonzoG
Posts: 426
Joined: Wed Jan 15, 2020 11:30 am
Answers: 30
Location: Prudnik, Poland

Re: A ds3231 library for the STM32 Blue Pill

Post by GonzoG »

ag123 wrote: Tue Jun 25, 2024 11:02 am stm32's rtc is quite stable / precise with a decent 32k LSI crystal.
...
in practical terms that works, reducing the monthly (or even over several months) variation to a minute or less.
...
That's not a precise clock. DS3231 with proper calibration achieves 1s/year. Even those cheap clones (~$1) from Aliexpress are <1s/month.

@ChPr
I have modified this library to add calibration, but did it without making a copy and it was replaced while it updated. Need to go through backups to check if it's saved somewhere.
ag123
Posts: 1748
Joined: Thu Dec 19, 2019 5:30 am
Answers: 27

Re: A ds3231 library for the STM32 Blue Pill

Post by ag123 »

STM32ardui wrote: Tue Jun 25, 2024 2:36 pm
ag123 wrote: Tue Jun 25, 2024 11:02 am stm32's rtc is quite stable / precise with a decent 32k LSI crystal.
?
LSE ?
yup LSE :)

@GonzoG Well, I've not played with ds32231 literally, perhaps that it is useful where accurate RTC is needed.
my main RTC usage is usually to time stamp log files on sd cards, for that purpose very high precision / accuracy often isn't required.
Hence, I made that little app that does that drift adjustments. It helped if a crystal is drifting by a relatively constant period.
And I'd sync the difference up say every month or few months or so, that keeps timing in line to a few minutes mostly.
I've been leaving such a logger for months and when i used it again months later, the drift is often less than 2-3 minutes if the calibration for the drift adjustment is properly done.
Last edited by ag123 on Tue Jun 25, 2024 6:53 pm, edited 1 time in total.
STM32ardui
Posts: 105
Joined: Mon May 06, 2024 1:46 pm
Answers: 1
Location: Germany

Re: A ds3231 library for the STM32 Blue Pill

Post by STM32ardui »

GonzoG wrote: Tue Jun 25, 2024 6:01 pm That's not a precise clock. DS3231 with proper calibration achieves 1s/year. Even those cheap clones (~$1) from Aliexpress are <1s/month.
From DS3231 datasheet:
Without calibration DS3231 has accuracy of ±2ppm from 0°C to +40°C.
Trim Register Frequency Sensitivity per LSB is 0,1 ppm at 25 °C.

I think "trim" is the same like "aging offset":

Code: Select all

The change in ppm per LSB is different at different tem-
peratures. The frequency vs. temperature curve is shifted
by the values used in this register. At +25°C, one LSB
typically provides about 0.1ppm change in frequency
A year has 60*60*24*365 = 31.536.000 s. So 0.1 ppm is 3,1 s - how do you achieve "1s/year"?
ag123
Posts: 1748
Joined: Thu Dec 19, 2019 5:30 am
Answers: 27

Re: A ds3231 library for the STM32 Blue Pill

Post by ag123 »

@STM32ardui I think sometimes observations and sheer luck (relatively unchanged environment factors e.g. constant temperature) could contribute to a higher observed accuracy. Those numbers are likely also stochastic in a sense that it probably falls in a 'bell curve', so if one bin the crystals and chips, one may luckily land some that is more accurate than the average ones.
even for my 'kitchen sink' drift adjuster, I've seen drifts less than a minute after months if the drift delta calibration is properly done.
I'd guess it is mostly 'luck' in a sense that environment (e.g. temperature) is unchanged pretty much.
But that I'm less bothered by that as I feel it is too much effort to focus on the precision / accuracy of the RTC when it isn't really designed to do that.
For real accurate time keeping, I'd guess regular time sync e.g. NTP or GPS would be necessary.
Post Reply

Return to “IDE's”