Skip to content

Handle reset time #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,23 @@ _Time and date configuration (added for convenience)_
* **`void getTime(uint8_t *hours, uint8_t *minutes, uint8_t *seconds, uint32_t *subSeconds, AM_PM *period = NULL)`**
* **`void getDate(uint8_t *weekDay, uint8_t *day, uint8_t *month, uint8_t *year)`**

### Since STM32 Core version > 1.5.0
_Reset time management_
By default, if a time is set it will not be reset afer a reboot.

Using `begin(true)` or `begin(true, HOUR_24)` will reset the RTC registers.

To know if a time has already been set use:
* **`bool isTimeSet(void)`**
```
if (!rtc.isTimeSet()) {
// Set the time
rtc.setHours(hours);
rtc.setMinutes(minutes);
rtc.setSeconds(seconds);
}
```

Refer to the Arduino RTC documentation for the other functions
http://arduino.cc/en/Reference/RTC

Expand Down
8 changes: 7 additions & 1 deletion src/STM32RTC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

// Initialize static variable
bool STM32RTC::_configured = false;
bool STM32RTC::_reset = false;

/**
* @brief initializes the RTC
Expand All @@ -54,6 +55,7 @@ bool STM32RTC::_configured = false;
*/
void STM32RTC::begin(bool resetTime, Hour_Format format)
{
_reset = resetTime;
if(resetTime == true) {
_configured = false;
_alarmEnabled = false;
Expand All @@ -71,7 +73,11 @@ void STM32RTC::begin(Hour_Format format)
if(_configured == false) {
RTC_init((format == HOUR_12)? HOUR_FORMAT_12: HOUR_FORMAT_24,
(_clockSource == LSE_CLOCK)? ::LSE_CLOCK:
(_clockSource == HSE_CLOCK)? ::HSE_CLOCK : ::LSI_CLOCK);
(_clockSource == HSE_CLOCK)? ::HSE_CLOCK : ::LSI_CLOCK
#if defined(STM32_CORE_VERSION) && (STM32_CORE_VERSION > 0x01050000)
, _reset
#endif
);
// Must be set before call of sync methods
_configured = true;
syncTime();
Expand Down
9 changes: 9 additions & 0 deletions src/STM32RTC.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,21 @@ class STM32RTC {
bool isAlarmEnabled(void) {
return _alarmEnabled;
}
bool isTimeSet(void) {
#if defined(STM32_CORE_VERSION) && (STM32_CORE_VERSION > 0x01050000)
return RTC_IsTimeSet();
#else
return false;
#endif
}

friend class STM32LowPower;

private:
STM32RTC(void): _clockSource(LSI_CLOCK) {}

static bool _configured;
static bool _reset;

AM_PM _hoursPeriod;
uint8_t _hours;
Expand Down