RTC RESET via software

Thanks it resolved one issue of date not getting populating.

What we can do for if rtc time get struck at particular time.and how we do that in code

afremont:
You need to send weekDay when you set the clock. You are not sending it, causing the following fields to get wrong data. In my first post in this thread, I have some code that will set the clock. I have also fixed my code that reads the clock. I haven't tested it yet.

  tempaddr = 0x68;

Wire.beginTransmission(tempaddr);
  Wire.write(0x00);  // set address to 0
  Wire.write(0x00);  // seconds in BCD
  Wire.write(0x19);  // minutes in BCD
  Wire.write(0x15);  // hours in BCD
  Wire.write(0x06);  // day of week        DONT FORGET THIS
  Wire.write(0x15);  // date
  Wire.write(0x02);  // month 
  Wire.write(0x13);  // year
  Wire.write(0x10);  // sq wave out 1HZ 
  Wire.endTransmission();

If the MSB of the seconds register is set to '1', the clock will not advance. MSB is bit 7 datasheet labels as CH bit.

AMPS-N:
What we can do for if rtc time get struck at particular time.and how we do that in code

Struck?

I have an Arduino which monitors things. It runs for, like, a year without any problems. The clock isn't the problem. More likely your hardware.

However on my link above (Gammon Forum : Electronics : Microprocessors : I2C - Two-Wire Peripheral Interface - for Arduino) is a link to an I2C library that does not hang if it doesn't get a response.

Which is header file.I have given my code below.And how it will check for responses

#include"Wire.h"

#define DS1307_ADDRESS 0x68
byte zero = 0x00; //workaround for issue #527

void setup(){
  Wire.begin();
  Serial.begin(9600);

 setDateTime(); //MUST CONFIGURE IN FUNCTION
}

void loop(){
  
  printDate();
  delay(1000);
}

void setDateTime(){

  byte second =45; //0-59
  byte minute =28; //0-59
  byte hour =7; //0-23
  byte weekday=2;
  byte monthDay =13; //1-31
  byte month =3; //1-12
  byte year  =13; //0-99
 


 Wire.beginTransmission(DS1307_ADDRESS);

  Wire.write(zero); //stop Oscillator

  Wire.write(decToBcd(second));
  Wire.write(decToBcd(minute));
  Wire.write(decToBcd(hour));
   Wire.write(decToBcd(weekday));
  Wire.write(decToBcd(monthDay));
  Wire.write(decToBcd(month));
  Wire.write(decToBcd(year));

  Wire.write(zero); //start

  Wire.endTransmission();

}

byte decToBcd(byte val){
// Convert normal decimal numbers to binary coded decimal
  return ( (val/10*16) + (val%10) );
}

byte bcdToDec(byte val)  {
// Convert binary coded decimal to normal decimal numbers
  return ( (val/16*10) + (val%16) );
}

void printDate(){

  // Reset the register pointer
  Wire.beginTransmission(DS1307_ADDRESS);
 
  Wire.write(0);
  Wire.endTransmission();

  Wire.requestFrom(DS1307_ADDRESS,7);

   int second = bcdToDec(Wire.read());
  int minute = bcdToDec(Wire.read());
  int hour = bcdToDec(Wire.read() & 0b111111); //24 hour time
  int weekday=bcdToDec(Wire.read());
  int monthDay = bcdToDec(Wire.read());
  int month = bcdToDec(Wire.read());
  int year = bcdToDec(Wire.read());

 /*  int second = 11;
  int minute =18;
  int hour = 18;
  int weekDay = 1;
  int monthDay = 2;
  int month = 11;
  int year = 12;
*/
  //print the date EG   3/1/11 23:59:59

  Serial.print(monthDay);
  Serial.print("/");
  
  
  Serial.print(month);
  Serial.print("/");
  
  Serial.print(year);
  Serial.print(" ");
  Serial.print(hour);
  Serial.print(":");
  Serial.print(minute);
  Serial.print(":");
  Serial.println(second);

}

Dear all,

for struck of date and time,i think like this way
i need function that will execute for every 1 minute. parameter it take time (hour:min:second).
for every 1 minute it check whether hour.min.sec has changed or not.

if hour.min.sec is changing
continue;
else
add 1 minute and write to RTC

how we can write in arduino platform.i dont want to use delay and miilis function.using counter how can we do that

You shouldn't have to do anything like that. When the clock is not advancing, you should see bit CH (Bit 7) set in the SECONDS register. That is the only problem I have ever encountered, and it may have been because I didn't have correct code when I accessed the clock. As Nick says, the clock should work reliably for months if not years without issue.

I just tested the code changes I made for reading the clock and my clock was only 10 seconds fast. It was last set on 15 Feb. I have modified the program to read the clock approx 30 times per second. I will let this run and see if it randomly stops advancing again. I don't expect it to since I used the same clock module on a PIC project where it ran for many months without issue.

@OP: Have you read my first reply? Did you check the voltages? DS1307 are known for striking if the power supply is not stable. I think you should check for that and correct it first and not try to tinker some pseudo solutions. The RTC should keep the time while the Arduino is not running. Theoretically you can read the time at startup and you don't need to bother with the RTC again till the next reset.

That's interesting pylon, could you tell more about what the problem is? I would think that with a backup battery, the chip should handle pretty much anything you throw at it, as far as messing with the power. Is it that it doesn't like a bunch of sharp glitches close together? Maybe just adding a big cap to the power pin to slow down the voltage changes?

I never had the problem myself but we've seen it a few times on this forum. When it happened a stabilization of the power supply solved it.

From the datasheet:

When VCC falls below 1.25 x VBAT the device terminates an access in progress and resets the device address counter. Inputs to the device will not be recognized at this time to prevent erroneous data from being written to the device from an out of tolerance system. When VCC falls below VBAT the device switches into a low-current battery backup mode.

A new battery gives about 3.5V so if the supply voltage drops below ca. 4.4V you might see such behavior.

Ok, well that sounds like predictable and designed in behavior even if it's not the nicest thing. I've had the CH bit get set for no apparent reason when the only code was to read from the clock chip. I know it wasn't writing arbitrary trash to the seconds register because the clock kept good time as long as it was running. Anything writing to the seconds register on a regular basis would cause horrible timekeeping so I'm pretty confident of that. I did have an error and I have changed it to see if the problem occurs again. I set the program up to read the clock about 30 times per second as that's what seemed to trigger it before.

The clock will keep running on the battery backup, but the I2C communication, which requires 4.5V to 5V, may be erratic if the power supply is erratic. The default library is known to hang if it doesn't get an interrupt it is expecting.

As I said earlier, on my link above (Gammon Forum : Electronics : Microprocessors : I2C - Two-Wire Peripheral Interface - for Arduino) is a link to an I2C library that does not hang if it doesn't get a response.

ya checked it properly. They are working seem properly during operation. But they get disturbed when voltage level are different

pylon:
@OP: Have you read my first reply? Did you check the voltages? DS1307 are known for striking if the power supply is not stable. I think you should check for that and correct it first and not try to tinker some pseudo solutions. The RTC should keep the time while the Arduino is not running. Theoretically you can read the time at startup and you don't need to bother with the RTC again till the next reset.

Some how i wanna try this code.

Is it possible to check code whther RTC running for every 1 min,If data is varying within 1 min continue process. else write new rtc time with l minute add to previous time. How to do this

Very similar topic here.

(sp. "want to")

Here i have written code that execute for every predefined second, If RTC stopped working for more predefine time , it rewrite the rtc time with previous time

test1.zip (2.23 KB)

You are totally fixing the wrong thing here. It's like saying "oh my fuse keeps blowing, but no matter, I've got a robot installed that pulls out the blown fuse and puts in a new one".

You have to fix the problem, not put a bandage over it.

Please elaborate this.

Can you able to give me the solution.How can avoid my fuse(ds1307) keep blowing. I wanna diagnostic output so that i should come to know RTC got damaged.
what is other kind of fuse(ds1307) i can use . which can take of voltage fluctuation and having internal crystal oscillator.

Have you installed the Wire library, that I have mentioned about three times now, that does not hang if it misses an interrupt? Or not?

i have wired liberary. I posted my code at begining.

AMPS-N:
i have wired liberary. I posted my code at begining.

Post your current code please.