Problem working with RTC DS1337.

I am trying to use a edited version of the library given at this link
http://forum.arduino.cc/index.php?topic=38077.0. I am able to use this library after some editing. Though i am not a hard core programming guy , but somehow i am always able to use some existing library. I made a sample code, just to write time to DS1337 and read from it. Below is the code

#include <DS1337.h>
#include <Wire.h>
#include <avr/power.h>
#include <avr/sleep.h>
int i;
DS1337 RTC = DS1337();

void setup(){
Serial.begin(9600);
if(!RTC.time_is_set())
  {
    Serial.println("Clock did not set, wtf? Check that its oscillator is working.");
  }
RTC.start();
    RTC.setSeconds(00);
    RTC.setMinutes(00);
    RTC.setHours(05);
    RTC.setDays(06);
    RTC.setMonths(3);
    RTC.setYears(2014);
RTC.writeTime();
}

void loop(){
  int i;
  for(i=0;i<=5;i++){
  RTC.readTime(); // update RTC library's buffers from chip
  printTime(0);
  delay(5000);
  Serial.print("\n");
    }
  }

void printTime(byte type)
{
  // Print a formatted string of the current date and time.
  // If 'type' is non-zero, print as an alarm value (seconds thru DOW/month only)
  // This function assumes the desired time values are already present in the RTC library buffer (e.g. readTime() has been called recently)

  if(!type)
  {
    Serial.print(int(RTC.getMonths()));
    Serial.print("/");  
    Serial.print(int(RTC.getDays()));
    Serial.print("/");  
    Serial.print(RTC.getYears());
  }
  else
  {
    //if(RTC.getDays() == 0) // Day-Of-Week repeating alarm will have DayOfWeek *instead* of date, so print that.
    {
      Serial.print(int(RTC.getDayOfWeek()));
      Serial.print("th day of week, ");
    }
    //else
    {
      Serial.print(int(RTC.getDays()));
      Serial.print("th day of month, ");      
    }
  }
  
  Serial.print("  ");
  Serial.print(int(RTC.getHours()));
  Serial.print(":");
  Serial.print(int(RTC.getMinutes()));
  Serial.print(":");
  Serial.print(int(RTC.getSeconds()));  
}

This code however give this output.Have a look at the enclosed image i.e DS1337 output.jpg

Now with this it is quite clear that my oscillator is not working, although i am able to set the date and time(but that time is not increasing ).Here is the wiring scheme which i used i.e. DS1337 wiring
I am unable to get what wrong i am doing. At present i am not using the alarm capabilities of the DS1337 , basically for which DS1337 is used.

Need help with this.

If I look here: http://www.maximintegrated.com/datasheet/index.mvp/id/3128

You should also use pull-up resistors for intA en intB.

By the way, it also looks like your arduino uses a 5V I2C bus and your DS1337 is connected to 3.3V.

And is your I2C-adress for the DS1337 defined anywhere?

yes I2C slave address for the DS1337 is defined in the header file.Enclosing the header file and library file for the same.

With respect to the 5V i2c bus used by the Arduino, when i looked at the DS1337 datasheet, it can possibly work with 1.8, 3.3 and 5.5 V all, to perform all the functionalities that a RTC can, but its typical voltage is 3.3 V. I had tried with both, but none of them worked.

and with respect to using PULL-UP resistor while using INTA and INTB , i think when i am not using them at present, it must not bother my main code or functionalities of the RTC.

srj0408: and with respect to using PULL-UP resistor while using INTA and INTB , i think when i am not using them at present, it must not bother my main code or functionalities of the RTC.

I looked at the datasheet and you're right, it is allowed to let them float.

In the datasheet on page 10 http://datasheets.maximintegrated.com/en/ds/DS1337-DS1337C.pdf I also found the following, maybe that will help you:

Control Register (0Eh) Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 EOSC 0 0 RS2 RS1 INTCN A2IE A1IE

Bit 7: Enable Oscillator (EOSC). This active-low bit when set to logic 0 starts the oscillator. When this bit is set to logic 1, the oscillator is stopped. This bit is enabled (logic 0) when power is first applied.

I hope that if it EOSC , the bit which you told is responsible for Oscillator ON/OFF mode, is 1 will not damage the Oscillator or DS1337. Earlier it was 1, but now i changed it to 0.

#define DS1337_SP           0x0E
#define DS1337_SP_EOSC      B00000000
#define DS1337_SP_RS2       B00010000
#define DS1337_SP_RS1               B00001000
#define DS1337_SP_INTCN     B00000100
#define DS1337_SP_A2IE      B00000010
#define DS1337_SP_A1IE      B00000001

But still the same result.I again tried changing the oscillator, but no results.

srj0408: I hope that if it EOSC , the bit which you told is responsible for Oscillator ON/OFF mode, is 1 will not damage the Oscillator or DS1337.

It won't harm the DS1337 nor the oscillator if you set it to 1.

Earlier it was 1, but now i changed it to 0.

Question is: How did it get '1' in the first place?

Try reading it out in runtime, maybe some part of your code is constantly setting it to 1.

I think i figured out the problem, but i am not sure though. I think its due to some registers settings

I my header file for DS1337, i am using these settings

#define DS1337_SP           0x0E
#define DS1337_SP_EOSC      B00000000
#define DS1337_SP_RS2       B00010000
#define DS1337_SP_RS1       B00001000
#define DS1337_SP_INTCN     B00000000
#define DS1337_SP_A2IE      B00000010
#define DS1337_SP_A1IE      B00000001

and in DS1337 datasheet , page 10 , its define what if we want to uyse 32.768 KHz crystal. Now when i work earlier, i use to use "0b" for binary and "0x" foir hexa decimal , now here what should i use, i am totally unaware of.

Bit 7: Enable Oscillator (EOSC). This active-low bit when set to logic 0 starts the oscillator. When this bit is set to logic 1, the oscillator is stopped. This bit is enabled (logic 0) when power is first applied.

Bits 4 and 3: Rate Select (RS2 and RS1). These bits control the frequency of the square-wave output when the square wave has been enabled. The table below shows the square-wave frequencies that can be selected with the RS bits. These bits are both set to logic 1 (32kHz) when power is first applied.

Bit 2: Interrupt Control (INTCN). This bit controls the relationship between the two alarms and the interrupt output pins. When the INTCN bit is set to logic 1, a match between the timekeeping registers and the alarm 1 registers l activates the INTA pin (provided that the alarm is enabled) and a match between the timekeeping registers and the alarm 2 registers activates the SQW/INTB pin (provided that the alarm is enabled). When the INTCN bit is set to logic 0, a square wave is output on the SQW/INTB pin. This bit is set to logic 0 when power is first applied.

Bit 1: Alarm 2 Interrupt Enable (A2IE). When set to logic 1, this bit permits the alarm 2 flag (A2F) bit in the status register to assert INTA (when INTCN = 0) or to assert SQW/INTB (when INTCN = 1). When the A2IE bit is set to logic 0, the A2F bit does not initiate an interrupt signal. The A2IE bit is disabled (logic 0) when power is first applied.

Bit 0: Alarm 1 Interrupt Enable (A1IE). When set to logic 1, this bit permits the alarm 1 flag (A1F) bit in the status register to assert INTA. When the A1IE bit is set to logic 0, the A1F bit does not initiate the INTA signal. The A1IE bit is disabled (logic 0) when power is first applied.

srj0408: I think i figured out the problem, but i am not sure though. I think its due to some registers settings

I my header file for DS1337, i am using these settings

#define DS1337_SP         0x0E
#define DS1337_SP_EOSC      B00000000
#define DS1337_SP_RS2       B00010000
#define DS1337_SP_RS1       B00001000
#define DS1337_SP_INTCN     B00000000
#define DS1337_SP_A2IE      B00000010
#define DS1337_SP_A1IE      B00000001

I dont know your header file, nor your library, but I think it should be something like this (I did not check the datasheet for corresponding bits, just an example derrived from what you provided)

#define DS1337_SP    B00011011

Anyway, dump the whole code above to see if you could get it working, on startup, the DS1337 should load default values on startup with oscillator == ON.