Skip to content

Commit

Permalink
Issue #35
Browse files Browse the repository at this point in the history
Setting Weekday overwrites 3 registers OSCRUN, VBATEN and PWRFAIL
  • Loading branch information
SV-Zanshin authored and SV-Zanshin committed Dec 15, 2018
1 parent 9736775 commit 0678a66
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
17 changes: 9 additions & 8 deletions src/MCP7940.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,9 +398,9 @@ DateTime MCP7940_Class::getPowerUp() { //
} // of method getPowerUp() // //

/*******************************************************************************************************************
** Method adjust set the current date/time. This is an overloaded function, if called with no parameters then the **
** RTC is set to the date/time when the program was compiled and uploaded. Otherwise the values are set, but the **
** oscillator is stopped during the process and needs to be restarted upon completion. **
** Method adjust() sets the current date/time. This is an overloaded function, if called with no parameters then **
** the RTC is set to the date/time when the program was compiled and uploaded. Otherwise the values are set, but **
** the oscillator is stopped during the process and needs to be restarted upon completion. **
*******************************************************************************************************************/
void MCP7940_Class::adjust() { // Set the RTC date and Time //
adjust(DateTime(F(__DATE__), F(__TIME__))); // Set to compile time //
Expand All @@ -410,7 +410,7 @@ void MCP7940_Class::adjust(const DateTime& dt) { //
writeByte(MCP7940_RTCSEC, int2bcd(dt.second())); // Write seconds, keep device off //
writeByte(MCP7940_RTCMIN, int2bcd(dt.minute())); // Write the minutes value //
writeByte(MCP7940_RTCHOUR, int2bcd(dt.hour())); // Also re-sets the 24Hour clock on //
writeByte(MCP7940_RTCWKDAY, dt.dayOfTheWeek()); // Update the weekday //
weekdayWrite(dt.dayOfTheWeek()); // Update the weekday //
writeByte(MCP7940_RTCDATE, int2bcd(dt.day())); // Write the day of month //
writeByte(MCP7940_RTCMTH, int2bcd(dt.month())); // Month, ignore R/O leapyear bit //
writeByte(MCP7940_RTCYEAR, int2bcd(dt.year() - 2000)); // Write the year //
Expand All @@ -427,13 +427,14 @@ uint8_t MCP7940_Class::weekdayRead() { //
} // of method weekdayRead() // //

/*******************************************************************************************************************
** Method weekdaywrite will write the weekday (1-7) to the register and return the setting. If the input value is **
** out of range then nothing will be written and a 0 will be returned. **
** Method weekdaywrite() will write the weekday (1-7) to the register and return the setting. If the input value **
** is out of range then nothing will be written and a 0 will be returned. The unused bits of the register are **
** preserved **
*******************************************************************************************************************/
uint8_t MCP7940_Class::weekdayWrite(const uint8_t dow) { // Write the DOW to the RTC //
uint8_t retval = 0; // assume we have an error //
uint8_t retval = (readByte(MCP7940_RTCWKDAY) & B11111000) | dow; // Read, mask DOW bits & add DOW //
if (dow > 0 && dow < 8) { // If parameter is in range, then //
writeByte(MCP7940_RTCWKDAY, dow); // set the register //
writeByte(MCP7940_RTCWKDAY, retval); // Write the register //
retval = dow; // set the return value //
} // of if-then we have a good DOW // //
return retval; // return the value //
Expand Down
11 changes: 6 additions & 5 deletions src/MCP7940.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,22 @@
** Vers. Date Developer Github ID Comments **
** ====== ========== =================== ======================================================================== **
** 1.1.4 2018-12-15 hexeguitar Issue #36 - Overflow on I2C_MODES datatype corrected **
** 1.1.4 2018-12-15 huynh213 Issue #35 - MCP7940.adjust() function resets the PWRFAIL and VBATEN **
** 1.1.3 2018-08-08 amgrays Issue #32 - invalid return on SetMFP corrected **
** 1.1.3 2018-08-05 HannesJo0139 Issue #31 - incorrect calibration trim on negative numbers **
** 1.1.2 2018-08-04 SV-Zanshin Issue #28 - added new calibrate() overload for frequency calibration **
** 1.1.2 2018-07-08 logicaprogrammabile Issue #26 - regarding hour bitmasks **
** 1.1.1 2018-07-07 SV-Zanshin Fixed bugs introduced by 14,20 and 21 **
** 1.1.1 2018-07-07 SV-Zanshin Fixed bugs introduced by 14, 20, and 21 **
** 1.1.1 2018-07-07 wvmarle Pull #21 - Additional changes **
** 1.1.1 2018-07-06 wvmarle Pull #20 - Numerous changes and enhancements **
** 1.1.0 2018-07-05 wvmarle Pull #14 - bug fixes to alarm state and cleaned up comments **
** 1.0.8 2018-07-02 SV-Zanshin Added guard code against multiple I2C constant definitions **
** 1.0.8 2018-06-30 SV-Zanshin Enh #15 - Added I2C Speed selection **
** 1.0.7 2018-06-21 SV-Zanshin Bug #13 - DateTime.dayOfTheWeek() is 0-6 instead of 1-7 **
** 1.0.6 2018-04-29 SV-Zanshin Issue #7 - Moved setting of param defaults to prototypes **
** 1.0.7 2018-06-21 SV-Zanshin Issue #13 - DateTime.dayOfTheWeek() is 0-6 instead of 1-7 **
** 1.0.6 2018-04-29 SV-Zanshin Issue #7 - Moved setting of param defaults to prototypes **
** 1.0.6 2018-04-29 SV-Zanshin Issue #10 - incorrect setting of alarm with WKDAY to future date **
** 1.0.5b 2017-12-18 SV-Zanshin Issue #8 - incorrect setting to 24-Hour clock **
** 1.0.5a 2017-10-31 SV-Zanshin Issue #6 - to remove classification on 2 template functions **
** 1.0.5b 2017-12-18 SV-Zanshin Issue #8 - incorrect setting to 24-Hour clock **
** 1.0.5a 2017-10-31 SV-Zanshin Issue #6 - to remove classification on 2 template functions **
** 1.0.4c 2017-08-13 SV-Zanshin Enhancement #5 to remove checks after Wire.requestFrom() **
** 1.0.4b 2017-08-08 SV-Zanshin Replaced readRAM and writeRAM with template functions **
** 1.0.4a 2017-08-06 SV-Zanshin Removed unnecessary MCP7940_I2C_Delay and all references **
Expand Down

0 comments on commit 0678a66

Please sign in to comment.