DS1307 not working properly

Hi

First of all, please excuse me if the post is not in the correct forum.

I am running the example DS1307 sketch of library RTClib.h to test my DS1307 chip.

a) The Oscillator is connected to pin 1 & 2
b) 3V power supply is connected across pin 3 & 4
c) Pull up 10k connected to pin 5 ----> Arduino A4
d) Pull up 10k connected to pin 6 ----> Arduino A5
e) Pull up 10k connected to pin 7 ----> 220R + LED to GND
f) Pin 8 to 5V from Arduino
g) Pin 4 to GND from Arduino

The output what I am getting on serial monitor is attached.


By the way, I don’t find any option to insert my uploaded image within the text. Would appreciate if someone could guide me how to do that.

Firstly the image insert icon is the one looking like a computer screen (sort of).

Secondly you don’t paste text as an image - that’s completely unsearchable. Copy/paste the text
into a code tagged section ‘</>’ icon…

Please post the sketch you are using, or a link to the example file (not just a description of
the library, libraries have various versions, some of which may be unofficial, wrong, etc etc).
Best to post the exact sketch in question.

You serial output shows that the RTC is not running. Presumably that example isn’t trying to
set it running, so its not running…

Here is the code of the example sketch:

// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
#include <Wire.h>
#include "RTClib.h"

#if defined(ARDUINO_ARCH_SAMD)
// for Zero, output on USB Serial console, remove line below if using programming port to program the Zero!
   #define Serial SerialUSB
#endif

RTC_DS1307 rtc;

char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

void setup () {

#ifndef ESP8266
  while (!Serial); // for Leonardo/Micro/Zero
#endif

  Serial.begin(57600);
  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }

  if (! rtc.isrunning()) {
    Serial.println("RTC is NOT running!");
    // following line sets the RTC to the date & time this sketch was compiled
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    // This line sets the RTC with an explicit date & time, for example to set
    // January 21, 2014 at 3am you would call:
    // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
  }
}

void loop () {
    DateTime now = rtc.now();
    
    Serial.print(now.year(), DEC);
    Serial.print('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.print(now.day(), DEC);
    Serial.print(" (");
    Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
    Serial.print(") ");
    Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);
    Serial.println();
    
    Serial.print(" since midnight 1/1/1970 = ");
    Serial.print(now.unixtime());
    Serial.print("s = ");
    Serial.print(now.unixtime() / 86400L);
    Serial.println("d");
    
    // calculate a date which is 7 days and 30 seconds into the future
    DateTime future (now + TimeSpan(7,12,30,6));
    
    Serial.print(" now + 7d + 30s: ");
    Serial.print(future.year(), DEC);
    Serial.print('/');
    Serial.print(future.month(), DEC);
    Serial.print('/');
    Serial.print(future.day(), DEC);
    Serial.print(' ');
    Serial.print(future.hour(), DEC);
    Serial.print(':');
    Serial.print(future.minute(), DEC);
    Serial.print(':');
    Serial.print(future.second(), DEC);
    Serial.println();
    
    Serial.println();
    delay(3000);
}

No link to the library though, so no idea what the code does still.

You need to provide all the information needed to recreate the issue you are experiencing, that’s
the first rule of reporting a problem, no guesswork.

You want effort on solving your problem, not some other problem due to guessing the
wrong library and getting sidetracked on that.

Where did you download the library from, and does it have a version number?

Here is the link

I seem to remember that you have to take care with the VBAT connection. You might try seeing if the clock runs when you connect pin 3 to GND instead of to 3V.

Don

floresta:
I seem to remember that you have to take care with the VBAT connection. You might try seeing if the clock runs when you connect pin 3 to GND instead of to 3V.

Don

Thanks Don, it worked! I think it worked when disconnecting the pin 3.

By the way, do you have experience of using RTClib.h ??

No. I use the DS3231 and either program it directly or use the DS3232RTC library. Similar restrictions with respect to VBAT apply to this chip as well.

Don

abuhafss:
Thanks Don, it worked! I think it worked when disconnecting the pin 3.

By the way, do you have experience of using RTClib.h ??

From the datasheet of the DS1307:

VBAT – Battery input for any standard 3V lithium cell or other energy source. Battery voltage must be held between 2.0V and 3.5V for proper operation.

Mark-

You have quoted one sentence from a long paragraph in an old version of the datasheet. That paragraph has moved in the Maxim versions of the datasheet and it now starts out ‘Backup Supply Input …’

In spite of the phrase ‘or other energy source’ in both datasheets, when I look at the entire paragraph, my impression is that VBAT is intended to be connected to some sort of battery (hence it’s name) which will then keep the timing circuits running if the main supply fails or is disconnected. The caution about series diodes possibly preventing proper operation might preclude the use of a 3V power supply in place of a battery.

The Maxim datasheet also states that if ‘a backup supply is not required, VBAT must be grounded.’ This is where my suggestion came from.

Don

Ah, so either 0V or in range 2V to 3.5V, I've only used an RTC a coin cell so didn't realize it was even
possible to run them otherwise.

If no backup power then of course you have to turn the oscillator on explicitly on power up
yourself, the RAM bits come up undefined from that state.

If it's a module, then you don't need 2 pullup resistors.

I have a C sketch for this module if you want.

wolfrose:
If it's a module, . . .

I doubt he is using a module since he specified the IC pin connections.

If it's a module, then you don't need 2 pullup resistors. . . .

Wouldn't that depend on the specific module?

. . . I have a C sketch for this module if you want.

Which module?

Don

I am using DS1307 chip not the ready-made module.

The things got better the other day when I followed Don’s trick. But since that day, the chip is not responding to the time update functions.

I have two chips and two crystal oscillators, I have replaced them but nothing improved. The Serial Monitor showing 153 (hours) and 165 (minutes).

Would like to mention that the Crystals I am using are salvaged from some other PCBs, their legs were short so I soldered 3" wire piece to each leg. For 3V, I am using 2 x AA batteries. If no batteries used then I simply short pins 3 & 4. Please see the attached photo for better understanding.

Kindly guide me where am I wrong.

Start by cutting all except 1/4" from your crystal leads. There’s a reason that ‘their legs were so short’.

Then get third AA cell or a 5volt supply, the DS1307 specifies a minimum of 4.5v for VCC.

While you are tinkering you should consider ordering a DS3231 module to replace the DS1307, it won’t cost much more than the additional battery and it will run on 2 AA cells.

Don

Thanks for your response, Don.

Okay, I will trim the legs of the Crystal and give my feedback tomorrow. However, I am wondering if the longs leads were causing any problem then how did it worked earlier?

You are suggesting me to get the third AA cell to make Vcc 4.5V but then how can I observe the results on Serial Monitor?

Next you also recommended DS3231, is there any advantage over DS3017 other than Vcc 3V?

Sorry about the third battery reference. For some reason I thought the batteries were your VCC supply and not VBAT. You don’t want to go above 3.5v for VBAT.

The DS3231 has a built-in crystal and the oscillator circuit is temperature compensated. It’s long term accuracy is far superior to that of the DS1307. It also contains two alarms.

You might want to try a different library and certainly a simpler program until you get the thing functioning.

EDIT: Here’s one to check out: https://github.com/PaulStoffregen/DS1307RTC

Don

I trimmed the leads of the oscillator but no change. :slightly_frowning_face:

I have got DS3231 module, I tested it with RTClib (which is also compatible for DS3231). The time keeping is okay but, the time could not be updated. I should try some other library.

By the way, I should also mention that I am using D12 and D13 of UNO with my 7-seg display module. Could they be interfering with the I2C communication?

floresta:
You might want to try a different library and certainly a simpler program until you get the thing functioning.

EDIT: Here's one to check out: https://github.com/PaulStoffregen/DS1307RTC

Are you recommending Paul's library for DS3231 or for DS1307?

Next, how to obtain 1 second pulse from the module to blink the colon of my display module?

abuhafss:
Next, how to obtain 1 second pulse from the module to blink the colon of my display module?

I just use millis() for that, BlinkWithOutDelay style. Call heartbeat() from loop():

void heartbeat()
{
  if (millis() - previousMillis >= heartbeatInterval)
  {
    colon = !colon;
    previousMillis = millis();
  }

  if (colon)
  {
    display.print(':');
  }
  else
  {
    display.print(' ');
  }

}//heartbeat

abuhafss:
. . . I have got DS3231 module, I tested it with RTClib (which is also compatible for DS3231). . . .

There are so many ‘RTC’ libraries out there that it is important to clearly specify exactly which one you are referring to and where you got it. I typically put the source in a comment when I ‘#include’ the library.

#include <DS3232RTC.h>   // https://github.com/JChristensen/DS3232RTC

. . . The time keeping is okay but, the time could not be updated. I should try some other library. . . .

The clock updates itself, I think you are referring to setting the time which I also found was a problem due to sketchy instructions or total lack thereof. Fortunately that only has to be done once.

Right now I am using the Christensen DS3232RTC library.

. . . Are you recommending Paul’s library for DS3231 or for DS1307? . . .

That particular library was written for the DS1307. I think it is the one I used back when I was still using the DS1307.

Don