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

Development v1.1.8 merge to master #51

Closed SV-Zanshin closed 3 years ago

SV-Zanshin commented 3 years ago

Description

Corrected a bug in the battery backup mode and cleaned up formatting using clang-format

Fixes # (issue) Issue #49 - battery backup error Issue #50 - clang-formatting

Type of change

Please delete options that are not relevant.

How Has This Been Tested?

Tested

Test Configuration:

Checklist:

Zanshin Logo

manaioussema commented 3 years ago

Thank you for your great work @SV-Zanshin . I tried the new version and yes it is working, but sometimes the code hangs as the first time. image

SV-Zanshin commented 3 years ago

What is important, I found, is that the 2 pull-up resistors to the I2C bus remain powered; initially I had them on the board with the MCP7940 and when I removed power then the I2C bus got hung up. I think that might be what is happening to you as well.

manaioussema commented 3 years ago

if that is the case why sometimes it works sometimes it doesn't? If i understand you well, then the VBAT pin and VCC will be connected.

SV-Zanshin commented 3 years ago

Without a pullup the state is undefined. There are numerous threads on the web about sporadic/indeterminate I2C behaviour without pull-ups.

When I shifted my pull-up resistors to the Arduino board and kept them to +5V (Arduino UNO and Micro test boards) and had my MCP7940N hooked up to 3.3V on the battery backup and then removed power to the MCP7940N then I got the expected results.

From: Manai Oussema notifications@github.com Sent: 16 November 2020 10:09 To: SV-Zanshin/MCP7940 MCP7940@noreply.github.com Cc: Arnd zanshin_github@sv-zanshin.com; Mention mention@noreply.github.com Subject: Re: [SV-Zanshin/MCP7940] Development v1.1.8 merge to master (#51)

if that is the case why sometimes it works sometimes it doesn't?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/SV-Zanshin/MCP7940/pull/51#issuecomment-727842660 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AFT5DREZPCVLLZ2ZPPZREI3SQDTZBANCNFSM4TWCBKDA . https://github.com/notifications/beacon/AFT5DRHWOW5ZHAZKH5C52U3SQDTZBA5CNFSM4TWCBKDKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOFNQ76ZA.gif

manaioussema commented 3 years ago

leaving the breakout aside, in real life scenario the power will be removed from the hole board (the one that i intend to use the RTC in), and therefore the I2C pull-ups will lose power.

SV-Zanshin commented 3 years ago

Yes, that is true and is not a problem, as the clock will resume working once power is re-applied.

But the demonstration program is different, it is designed to check the MCP7940 using I2C and thus the pull-ups need to be powered otherwise it can “hang”; and when it restarts it also set the clock. It is not designed as a solution for battery backup issues, but as a demonstration as to how the battery backup functions can be used.

From: Manai Oussema notifications@github.com Sent: 16 November 2020 10:28 To: SV-Zanshin/MCP7940 MCP7940@noreply.github.com Cc: Arnd zanshin_github@sv-zanshin.com; Mention mention@noreply.github.com Subject: Re: [SV-Zanshin/MCP7940] Development v1.1.8 merge to master (#51)

leaving the breakout aside, in real life scenario the power will be removed from the hole board (the one that i intend to use the RTC in), and therefore the I2C pull-ups will lose power.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/SV-Zanshin/MCP7940/pull/51#issuecomment-727854000 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AFT5DRHXFELYTVQPRCEHZWLSQDWDLANCNFSM4TWCBKDA . https://github.com/notifications/beacon/AFT5DRH6ZEWZWCP2JH474RDSQDWDLA5CNFSM4TWCBKDKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOFNRCXMA.gif

manaioussema commented 3 years ago

i see what you mean, however i soldered the pull-ups to the VBAT pin and put a 3.3V to that pin then i disconnected the power from VCC and i still get the to "hang".

manaioussema commented 3 years ago

After soldering back the pull-ups to VCC and putting the back the VBAT pin to the coin cell, i modified the code to not check periodically for the power loss and deleted the adjust in the setup, i kept plugging and unplugging the board from the usb and i quite got what would be the real-life scenario. As you said, the power being applied back will start the oscillator and get everything working back. I truly thank you for your help, wish you all the best. By the way, can you tell me what is the modification that you made in the library?

SV-Zanshin commented 3 years ago

I changed the error handling for I2C around a bit so that it wouldn't reset the MCP7940; you can compare the 2 versions in GIT to get the exact changes made.

manaioussema commented 3 years ago

i see, thank you.