Go Down

Topic: RTC DS1307 restarting when I disconnect ground. (Read 333 times) previous topic - next topic

Itaquito

Hey! I have my RTC DS1307 setup as following:



I setup the time with the following code and it all works fine, the time is correctly setup on the chip:

Code: [Select]
#include <Wire.h>
#include "RTClib.h"

RTC_DS1307 rtc;

void setup () {
  Serial.begin(9600);
  rtc.begin(); //Inicializamos el RTC
  Serial.println("Estableciendo Hora y fecha...");
  rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  Serial.println("DS1307 actualizado con la hora y fecha que se compilo este programa:");
  Serial.print("Fecha = ");
  Serial.print(__DATE__);
  Serial.print("  Hora = ");
  Serial.println(__TIME__);
}

void loop () {
}


Then I use this code to see the date of the chip and it does work, the date appears on the serial monitor:

Code: [Select]
#include <Wire.h>
#include "RTClib.h"

RTC_DS1307 rtc;

int segundo,minuto,hora,dia,mes;
long anio; //variable año
DateTime HoraFecha;

void setup () {
  Serial.begin(9600);
  rtc.begin(); //Inicializamos el RTC
 
}

void loop () {
    HoraFecha = rtc.now(); //obtenemos la hora y fecha actual
   
    segundo=HoraFecha.second();
    minuto=HoraFecha.minute();
    hora=HoraFecha.hour();
    dia=HoraFecha.day();
    mes=HoraFecha.month();
    anio=HoraFecha.year();

    //Enviamos por el puerto serie la hora y fecha.
    Serial.print("hora = ");
    Serial.print(hora);
    Serial.print(":");
    Serial.print(minuto);
    Serial.print(":");
    Serial.print(segundo);
    Serial.print("  Fecha = ");
    Serial.print(dia);
    Serial.print("/");
    Serial.print(mes);
    Serial.print("/");
    Serial.print(anio);
    Serial.println();
    delay(1000);
}


and this is where the problems appear, if I disconect the ground from the RTC DS1307 of the arduino it restarts the time back to 0:0:0 1/1/200, this doesnt happens if I disconnect the 5v, also the time gets restarted once I turn off the arduino.

I checked the voltage of the battery directly from the battery and from the chip and it all seems good (3v).

Any idea why this happens?

Thanks!

jremington

#1
Jun 14, 2019, 03:57 am Last Edit: Jun 14, 2019, 04:00 am by jremington
It is a bad idea to disconnect ground, as you have discovered.

One of the Arduino output pins might act as ground instead, allowing power to flow backwards through an input and possibly, destroying the RTC chip or even the Arduino.

In general, always disconnect or turn off all power sources before changing ANY wiring.

Idahowalker

Does your RTC have a battery backup attached?


Itaquito

It is a bad idea to disconnect ground, as you have discovered.

One of the Arduino output pins might act as ground instead, allowing power to flow backwards through an input and possibly, destroying the RTC chip or even the Arduino.

In general, always disconnect or turn off all power sources before changing ANY wiring.
Humm, this also happens when I disconnect my arduino from my PC.. :c

Does your RTC have a battery backup attached?


Yep! and it also gives 3v to the chip

MarkT

and this is where the problems appear, if I disconect the ground from the RTC DS1307 of the arduino it restarts the time back to 0:0:0 1/1/200, this doesnt happens if I disconnect the 5v, also the time gets restarted once I turn off the arduino.

I checked the voltage of the battery directly from the battery and from the chip and it all seems good (3v).

Any idea why this happens?
If you read the datasheet you'll see that when Vcc drops below Vbat is what puts the chip into power down mode and stop responding to commands.  This is the intended mode of operation.  Disconnecting ground might do anything, the chip designers definitely did not intend this.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

Itaquito

If you read the datasheet you'll see that when Vcc drops below Vbat is what puts the chip into power down mode and stop responding to commands.  This is the intended mode of operation.  Disconnecting ground might do anything, the chip designers definitely did not intend this.
So, this means I cannot disconnect my arduino from power?

cattledog

Quote
So, this means I cannot disconnect my arduino from power?
You certainly can, but it appears that something is wrong with the battery power for the module. How have you have confirmed voltage at the chip pin is 3v? Is the battery installed with the + facing out. Are you certain you are measuring the correct pin on the chip?

Can you try a new battery?

If the voltage is present but the rtc is not running, then you may have a defective chip or oscillator on the module. See this thread for a case of a counterfeit ds1307 chip which would not run under battery power http://forum.arduino.cc/index.php?topic=303406.0

Where does the module come from?

Itaquito

You certainly can, but it appears that something is wrong with the battery power for the module. How have you have confirmed voltage at the chip pin is 3v? Is the battery installed with the + facing out. Are you certain you are measuring the correct pin on the chip?

Can you try a new battery?

If the voltage is present but the rtc is not running, then you may have a defective chip or oscillator on the module. See this thread for a case of a counterfeit ds1307 chip which would not run under battery power http://forum.arduino.cc/index.php?topic=303406.0

Where does the module come from?
With a Multimeter, I checked the battery itself and also the ports on the chip, so I know the socket is not defective.

One thing that happens is that when I disconnect the VCC the timer remains counting, so this confirms the reason that the chip and the battery is working.

I got it from a shop here in Mexico, probably it comes from china.

cattledog

#8
Jun 16, 2019, 04:11 am Last Edit: Jun 16, 2019, 04:13 am by cattledog
Quote
One thing that happens is that when I disconnect the VCC the timer remains counting, so this confirms the reason that the chip and the battery is working.

I got it from a shop here in Mexico, probably it comes from china.
By "timer remains counting" do you mean that can see square wave output with Vbat, but the clock does not advance the time registers using Vbat?

Infact, from your earlier postings it sounds like the clock registers are reset to 0 when Vcc is disconnected and the chip is running on Vbat. 

If this is the case, I would think that the module is defective and you should try and return it if possible. If you are going to get a new RTC, I would suggest an upgrade to a DS3231 as they are about the same cost as a DS1307 but are significantly more accurate time keepers and have some additional functionality like Alarms.

tigger

It might be better for the poster to get some genuine Maxim DS1307 chips in DIP form and make up a small breadboard so at least parts are replaceable before venturing into small outline. Plenty of tutorials out there to read first. We all make mistakes with power etc., but deliberately pulling out the ground is not a good idea,in fact it is the last thing that should be pulled. I have often wondered why motor manufacturers advise disconnecting the ground (-ve) on a car battery before disconnecting the positive.

cattledog

Quote
I have often wondered why motor manufacturers advise disconnecting the ground (-ve) on a car battery before disconnecting the positive.
My understanding is that it is a safety precaution. If the wrench or a ring on a finger of the hand holding the wrench contacts the frame(ground) there won't be any burns, sparks, or leaky fuel set on fire.

Go Up