Zanduino / MCP7940

Arduino Library to access the MCP7940M, MCP7940N and MCP7940x Real-Time chips
GNU General Public License v3.0
35 stars 22 forks source link

MCP7940.adjust() function reset the PWRFAIL and VBATEN #35

Closed HHH-01 closed 5 years ago

HHH-01 commented 5 years ago

The adjust() function resets the RTCWDAY, PWRFAIL bit and VBATEN bit somehow; this function should only affect the WDAY2-WDAY0 bits?

So if you use a backup battery and multiple adjust() functions in the main loop, the battery will be disabled whenever you call the adjust() function moving forward.

SV-Zanshin commented 5 years ago

Looking into the possible causes of this problem

SV-Zanshin commented 5 years ago

When the library sets the weekday, it cleared the OSCRUN, VBATEN and PWRFAIL register bits which caused the error. The fix is to only set the 3 relevant bits for the DOW and leave the rest of the register unchanged. Good catch!