I2C RTC DS1307 AT24C32 timer

hi

i just got I2C RTC DS1307 AT24C32 timer
i checked the 2IC adress with scanner the results was

I2C scanner. Scanning ...
Found address: 80 (0x50)
Found address: 104 (0x68)
Done.
Found 2 device(s).

That if i power to +5v if i remove power cant find any devices..

when the DS1307 is with the power +5v on it is able to read the time and date that gets from the computer, but if i remove power from it , is not able to read,the time is not counting. from what i read it looks like u got to enable the D1307 oscilator, the scketch i been using to try is

#include <Wire.h>
#include <Time.h>
#include <DS1307RTC.h>

void setup() {
  Serial.begin(9600);
  while (!Serial) ; // wait for serial
  delay(200);
  Serial.println("DS1307RTC Read Test");
  Serial.println("-------------------");
}

void loop() {
  tmElements_t tm;

  if (RTC.read(tm)) {
    Serial.print("Ok, Time = ");
    print2digits(tm.Hour);
    Serial.write(':');
    print2digits(tm.Minute);
    Serial.write(':');
    print2digits(tm.Second);
    Serial.print(", Date (D/M/Y) = ");
    Serial.print(tm.Day);
    Serial.write('/');
    Serial.print(tm.Month);
    Serial.write('/');
    Serial.print(tmYearToCalendar(tm.Year));
    Serial.println();
  } else {
    if (RTC.chipPresent()) {
      Serial.println("The DS1307 is stopped.  Please run the SetTime");
      Serial.println("example to initialize the time and begin running.");
      Serial.println();
    } else {
      Serial.println("DS1307 read error!  Please check the circuitry.");
      Serial.println();
    }
    delay(9000);
  }
  delay(1000);
}

void print2digits(int number) {
  if (number >= 0 && number < 10) {
    Serial.write('0');
  }
  Serial.print(number);
}

from what im understanding i need to enable the oscilator?
what is the code missing for be able to work with the batery with out the power?

meph328:
hi

i just got I2C RTC DS1307 AT24C32 timer

That if i power to +5v if i remove power cant find any devices..

when the DS1307 is with the power +5v on it is able to read the time and date that gets from the computer, but if i remove power from it , is not able to read,the time is not counting. from what i read it looks like u got to enable the D1307 oscilator, the scketch i been using to try is

from what im understanding i need to enable the oscilator?
what is the code missing for be able to work with the batery with out the power?

Ok, you need set the time at least once.

Fill in the tm record with Second,Minute,Hour,Wday,Day,Month,Year.

// set time to 20JUN2015 00:01:00
tm.Second =0;
tm.minute =1;
tm.hour=0;
tm.wday=0
tm.day=20;
tm.month=6;
tm.year=2015;

Then call RTC.write(tm). This will set the time and turn on the clock.

RTS.write(tm);  //set time and Start Clock

If you are seeing this message.

The DS1307 is stopped. Please run the SetTime example to initialize the time and begin running

You have two possible problems:

  1. your battery is not connected, or is dead

  2. The clock has never been set, or the battery went dead and the clock reset.

Fix the battery, then Set the time.

Chuck.


Check out my Kickstarter Project Memory Panes an expansion RAM Shield for Mega2560's. It adds 1MB of RAM for those projects where 8KB is not enough.

its possible post a exemple of the set time scketch with the time already set to make the oscilator star ?been trying but no able to do it grr

thanks

meph328:
its possible post a exemple of the set time scketch with the time already set to make the oscilator star ?been trying but no able to do it grr

thanks

Here is a sketch with trouble shooting.

I have attached my modified Copy of Wire.
If you use the default Wire library you will just have to comment out one error test.
I was seeing an error with my DS1307, it failed to respond on a random basis. I identified the issue as a timing problem. While the DS1307 is updating it's internal counters, it will not respond to requests.
I am polling it continuously, So I see the TW_MT_SLA_NAK (0x20) error. No acknowledge from Slave.

Streaming5 makes it easier to code error messages.

Chuck.


Check out my Kickstarter Project Memory Panes an expansion RAM Shield for Mega2560's. It adds 1MB of RAM for those projects where 8KB is not enough.

Wire.zip (16.1 KB)

Streaming5.zip (2.69 KB)

Clocker.ino (3.14 KB)

meph 328

when the DS1307 is with the power +5v on it is able to read the time and date that gets from the computer, but if i remove power from it , is not able to read,the time is not counting. from what i read it looks like u got to enable the D1307 oscilator

You can not read the time from the RTC under battery power alone. The module will keep track of time, but it can not be addressed without power. If the module does not keep track of time under battery power, there is a problem.

If you could set the time on the ds1307 to the compile time from the computer, the oscillator bit should be set. In the examples which come with the ds1307 library there is a SetTime sketch and a ReadTime sketch. Run SetTime, and then run ReadTime. The oscillator should be set, and the ds1307 will keep time on the battery. power. Make sure you do not just repower the arduino with the SetTime sketch loaded, or it will go back to the compile time.

You can use this code to verify that bit7 (ClockHalt) of register 0x00 is 0 and the oscillator is enabled.

// DS1307 I2C Read and Write Timekeeper Registers 0x00-0X07
#include "Wire.h"
#define DS1307_I2C_ADDRESS 0x68
#define startRegister 0x00
#define endRegister 0x07
//data storage registers 0X08-0X3F

void setup()
{
  Wire.begin();
  Serial.begin(9600);
  Serial.print("Register");
  Serial.print("\t");
  Serial.println("Bit Values");
  Serial.println();

  //writeNVRAM(0x00, B00000000);//enable oscillator and set seconds to 0
  //writeNVRAM(0x00, B10000000);//disable oscillator set CH bit

  for (int a = startRegister; a <= endRegister; a++)
  {
    byte b = readNVRAM(a);
    Serial.print("0X");
    if (a < 16)
      Serial.print("0");
    Serial.print(a, HEX);
    Serial.print("\t");
    Serial.print("\t");


    for (int i = 7; i >= 0; i-- )
    {
      Serial.print((b >> i) & 0X01);//shift and select first bit
    }
    Serial.println();
  }
}

void writeNVRAM(byte location, byte data)
// writes data to DS1307 NVRAM location
{
  Wire.beginTransmission(DS1307_I2C_ADDRESS);
  Wire.write(location);
  Wire.write(data);
  Wire.endTransmission();
}

byte readNVRAM(byte location)//// reads data from DS1307 NVRAM location
{
  Wire.beginTransmission(DS1307_I2C_ADDRESS);
  Wire.write(location);
  Wire.endTransmission();
  Wire.requestFrom(DS1307_I2C_ADDRESS, 1);
  Wire.read();
}

void loop() {
}

If the RTC is indeed halting at the time power is actually removed, then you have a problem in that the rtc is not running under battery power. There is likely something defective with the battery and its connection to the chip, or the ds1307 chip itself. Try a new battery, and set the time. If the time is not updated under battery power, you will then need to confirm that approximately 3 v is getting to the Vbat lead of the chip. If that's the case, 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 DS1307 Real Time Clock CH bit problem - Project Guidance - Arduino Forum