I am using a Nucleo L476RG board.My intention is to simply build a clock (not using any external RTC chips like DS3231).So,I removed the SB45 Bridge(0 ohm resistor which was connecting Vbat to Vdd) & connected a 3v Coin cell to the Vbat pin(Morpho connector #33).
Now to set the time,my sketch is as follows:
#include <STM32RTC.h>
/* Get the rtc object */
STM32RTC& rtc = STM32RTC::getInstance();
const byte seconds = 0;
const byte minutes = 15;
const byte hours = 23;
const byte weekDay = 1;//(Monday = 1)
const byte day = 10;
const byte month = 12;
const byte year = 18;
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
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.println();
delay(1000);
}
void print2digits(int number) {
if (number < 10) {
Serial.print("0"); // print a 0 before if the number is < than 10
}
Serial.print(number);
}
I will move the topic under to corresponding group.
1st you need to mention which is the core that you are using
2nd check your VBAT etc again. Are you sure VBAT is hooked up? assuming that you do not set the time, so that it starts running from 1-1-1970 00:00:00
check that it runs say for 30 secs
if you remove power leaving VBAT connected and then reconnect power and check the time again,
the time should continue from after 1-1-1970 00:00:30 i.e. the RTC runs on VBAT and should show the elapsed time
and you won’t even need to set the time
Please help to identify the problem……
Moreover someone spot my reply in red.
[fpiSTM – Mon Dec 10, 2018 8:30 pm] –
Currently, the backup register is not handled. An issue is already open for that.
This means when you reset the time is NOT restored.
This is not a bug nor a hardware issue. This is simply a not implemented feature and this will be implemented when I can have some time or if a contributor can help.
Seriously, you read when we comment ?
No,no…I read your reply!I wrote it in reply by user ag123
[SHARANYA – Tue Dec 11, 2018 6:00 am] –
In order to check if my hardware part is faulty,I loaded Micropython in the Nucleo board & wrote a small python script to show time from the RTC(Set time once & deleted that part of the script).
This time,it is running as expected without losing the register values.
So,clearly there is no problem with the hardware part
Hmm, how is this possible when:
[fpiSTM – Mon Dec 10, 2018 8:30 pm] –
Currently, the backup register is not handled. An issue is already open for that.
?
This is not a bug nor a hardware issue. This is simply a not implemented feature and this will be implemented when I can have some time or if a contributor can help.
If you want an example of one possible implementation, take a look at the code for the RTC in Rodger’s STM32F103XX repo. The layout of the registers is different I suspect, but the methods and features required will be similar. It ‘aint rocket surgery you know.