DS3231RTC error

I’m trying the TimeRTC example downloaded from:
GitHub - JChristensen/DS3232RTC: Arduino Library for Maxim Integrated DS3232 and DS3231 Real-Time Clocks.
when I compile it gives me the following error.

src/main.cpp:12:25: error: request for member 'get' in '(RTC_TypeDef*)(1073741824 + 10240)', which is of pointer type 'RTC_TypeDef*' (maybe you meant to use '->' ?)
   12 |     setSyncProvider(RTC.get);   // the function to get the time from the RTC

I am using:
VS code on linux mint
stlink as the upload protocol

[env: bluepill_f103c8]
platform = ststm32
board = bluepill_f103c8
framework = arduino
lib_deps =
   jchristensen/DS3232RTC@0.0.0-alpha+sha.261ca7d0e6
   paulstoffregen/Time@^1.6

As you can see in the code

Only in the AVR architecture, an object called RTC is created. If you do this in the STM32 environment, a global object or vialable called RTC would directly conflict with the RTC peripheral defintion of STM32 device header.

so you should never ever, do that.

If you are basing yourself off of the sketch at DS3232RTC/examples/TimeRTC/TimeRTC.ino at master · JChristensen/DS3232RTC · GitHub, just create your own global object as in

DS3232RTC externalRTC;

and then call setSyncProvider(externalRTC.get); instead of the old call.

Of course, using an external RTC while the STM32F103 has its own internal one begs the question of why a DS3231 is used at all. The bluepill already has a nice 32.768kHz crystal connected to its LSE and the RTC can use it.

First of all I thank you for the very fast and working response.

Now I have the problem of setting the date and time, which for the moment displays the wrong date and time and I don’t know how to do it.
It would be enough for me to read the system time (+ possible compilation time), how can I solve this problem?

Being an electronics enthusiast, a few months ago (lockdown) I came up with the idea of equipping the old off-road vehicle with a compass, clock, artificial horizon and altimeter. I started the project with arduino uno, which seemed to me to be considered more, but in the end the speed was not low as the memory was insufficient and so I switched to stm32.
For now I have not worried about the deepening of the internal functioning, but I think that if not the external rtc, when I turn off the car the time resets.
I also tried it with “Timezone” and it gives me the same problem.

The library has an example available for accepting the current time over a serial connection. Depending on how exact the current time has to be, you might want to write a Python script which opens the COM port, sends the time string, and closes the connection. Otherwise entering “by hand” one time in the serial monitor might suffice.

One-time of course only when the RTC is battery-backed, so it has its own battery / coin cell connected which holds its memory contents. Without battery-backup, disconnecting the board from power will delete the time as well.

Also if (really) long-term RTC accuracy is wanted, you may also need some sort drift compensation, depending on the RTC hardware.

Of course other methods of time synchronization exists. Over a internet network, this is usually done via NTP. GPS is also available, among other RF based synchronization methods (like the DFC77 time synchronization radio station in Germany).

I’m marking this thread as solved since the compilation problem is gone.

Thanks, I was able to set the correct date.
I have a question about the ds3231: when I completely turn off all devices (5V power supply) including stm32, the serial returns me a random date and time, (also changing the USB connection port) is it correct or I am wrong. How can I solve the problem ?

If I understand you correctly, you have completely powered off the 5V devices, but when you try and access one of them, the Real Time Clock, you get a random date/time and the port you have to connect to is different?

If so,

  • Your random date/time is to be expected as the communications between your main device and the RTC are, probably, no longer powered as you have killed the 5V supply. I’m surprised that you are getting any data back to be honest!
  • Your original port will have been communicating with the 5V system, you have killed that so that port will have no choice but to disconnect. It shouldn’t reconnect, even on a different port, until the 5V supply is reconnected. Again though, I’m not sure why or how you are managing to communicate with an effectively dead sub-system.

Can you correct this? well, yes. Don;t power down the 5V sub-systems and expect to be able to still communicate!

As I mentioned, I’m hoping I understood the question. Apologies if I’m off base.

Cheers,
Norm.

questo è lo schema dei collegamenti.schema
The USB printing problem was encountered only with the serial monitor of the arduino IDE and not with VS Code.
Both the breadbord with the devices and the Bluepills STM32 board are powered via USB.
I thought that disconnecting the USB connector of the PC, the DS3231, would keep me the correct data and time, otherwise the CR2032 battery, what’s the point?

anyway I thank you for your patience

The battery should indeed keep the DS3231 powered and therefore keep correct date and time. If your’s is not, then:

  • Is the battery in correctly? My RTC board is also a DS3231 and the battery is showing the +ve side uppermost, -ve closest to the PCB.
  • Does the battery still have charge? it should be 3V.
  • Your DS3231 might be faulty if the battery is correctly inserted and has charge.

I plugged my DS3231 in just now, after a few months being in the “spares box” and it’s still showing the correct data and time.

HTH

Cheers,
Norm.

<I’ve already tried to aim for battery and module replacement, but nothing has changed. what I noticed that if I unplug (power) the module, and plug it back in, it keeps the correct date and time. If I disconnect the power to the board, stm32 resets all values.
Is there no way to avoid the new setup?
In the next few days, I will try with a ds1307 module and the replacement of the STM32 bluepills with arduino uno and with mini maple.

In order to to answer any questions one would surely need to see the full schematic diagram of the setup. Then again this sounds like an electrical problem; nothing related to PlatformIO anymore. Other communities like https://electronics.stackexchange.com/ or https://arduino.stackexchange.com/ might help you better there.

If the RTC keeps time when unplugged and back in, then that’s ok.

If the STM32 resets the RTC then I suspect that there is some initialisation code that’s doing it because, at least on my DS3231, there isn’t a pin that can be pulled low or high to reset the entire clock.

HTH

Cheers,
Norm.