[Pending Enhancement] RTC values resetting

SHARANYA
Mon Dec 10, 2018 6:31 pm
Hi all
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);
}


stevestrong
Mon Dec 10, 2018 7:46 pm
Which core do you use? Generic or the official ST one?
I will move the topic under to corresponding group.

ag123
Mon Dec 10, 2018 8:04 pm
agree with steve
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

fpiSTM
Mon Dec 10, 2018 8:30 pm
Currently, the backup register is not handled. An issue is already open for that.

SHARANYA
Mon Dec 10, 2018 9:21 pm
I downloaded the cores from this link.This core is by ST.


https://github.com/stm32duino/BoardMan … ndex.json


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 & something wrong with the Arduino code!!
Please help to identify the problem……

fpiSTM
Tue Dec 11, 2018 8:10 am
Seriously, you read when we comment ?
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.


SHARANYA
Tue Dec 11, 2018 2:08 pm

Seriously, you read when we comment ?

No,no…I read your reply!I wrote it in reply by user ag123


stevestrong
Tue Dec 11, 2018 2:57 pm
[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.

?


SHARANYA
Tue Dec 11, 2018 5:36 pm
As fpiSTM said….


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.


ahull
Wed Dec 12, 2018 4:56 am
At the risk of starting a flame war, rather than arguing about the matter, why not implement the feature and post your code for review. This is what open source software is all about.

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. ;)


Leave a Reply

Your email address will not be published. Required fields are marked *