When arduino board is reset DS1307 resets too!

Hi,

I´m using the DS1307 RTC from Tigal (http://tigal.at/product/1599) with the libray from the playground (TIME & DS1307RTC).

I managed to set the DS1307 to the actual time and date but when I´m reseting the Arduinoboard the RTC is reset to 00:00:00 31.12.1999 when I´m calling

setSyncProvider(RTC.get);   // the function to get the time from the RTC
      if(timeStatus()!= timeSet) 
         Serial.println("Unable to sync with the RTC");
      else
         Serial.println("RTC has set the system time");

in the setup {} when not RTC is reset to 00:00:00 1.1.1970

Does anybody of you know this problem or even better how i can get rid of it?

Greetings
Stefan

I managed to set the DS1307 to the actual time and date

Using?

in the setup {} when not RTC is reset to 00:00:00 1.1.1970

All the words are recognizable, but the semantic content, when they are arranged in that order, is NULL. Please try again.

The Time Library keeps track of time. The time is set from a variety of sources, such as the RTC. The confusing step is that you can then set the time used by the Time library independent of the RTC. You are only setting the time inside your sketch and not actually writing it to the RTC.

For example:

if(timeStatus()!= timeSet)  //Doesn't check the RTC.

long pctime = 1322518310;  // number of seconds since epoch

setTime(pctime);  // This sets the time in the library
RTC.set(pctime);  // This sets the time into the RTC.

Until you call RTC.set() the RTC isn't actually being used for anything.

The problem is... when you reset the arduino, how do you know not to write to the RTC??

bubulindo: The problem is... when you reset the arduino, how do you know not to write to the RTC??

A separate sketch should be used to program the RTC. Or there should be hooks to only program the RTC in certain conditions. For example, on my binary clock I send a 'T' followed by the seconds since epoch over serial. In that situation, the RTC is set.

[quote author=James C4S link=topic=80583.msg609109#msg609109 date=1322525135]

bubulindo: The problem is... when you reset the arduino, how do you know not to write to the RTC??

A separate sketch should be used to program the RTC. Or there should be hooks to only program the RTC in certain conditions. For example, on my binary clock I send a 'T' followed by the seconds since epoch over serial. In that situation, the RTC is set. [/quote]

I was just raising the question for the OP to be careful since he may experience the same behavior if that particular aspect of the code is not set correctly. Nice of you to answer.

Hi thanks for the replys.

I think I haven´t explained my problem properly.

So I´ll try once again.

I´m using the RTC and a 4D System Display (with the Libary from ReiVilos HP : http://sites.google.com/site/vilorei/arduino/13--serial-touch-320x240-lcd-screen)where I´m displaying the time from the RTC and a touchbutton to trigger the setTime of the RTC.

#include <Serial_LCD.h>
#include <proxySerial.h>
#include <button.h>
#include <Wire.h>


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


#include "NewSoftSerial.h"
NewSoftSerial myNSS(2, 3);
ProxySerial mySerial(&myNSS);


Serial_LCD myLCD( &mySerial);  //Init myLCD

uint16_t x, y; //Touchcoordinates


button bStop( &myLCD); //init buttonStop
button bSetTime( &myLCD); //init buttonSetTime


void setup() { //Setup
  
  Serial.begin(19200);
  Serial.print("\n\n\n***\n");
  
  

//  // === Serial port initialisation
//  // --- SoftwareSerial Case - Arduino only
  myNSS.begin(9600);
  Serial.print("SoftwareSerial\t");
  Serial.print("\n");


  myLCD.begin(); //start myLCD

  delay(10);
  myLCD.setSpeed(38400);  

//  // === Serail port speed up
//  // --- SoftwareSerial Case - Arduino only
  myNSS.begin(38400);

  myLCD.setOrientation(0x03); // sets the orientation of the  Display

  myLCD.setPenSolid(true);
  myLCD.setFontSolid(true);

  myLCD.setFont(0);
  myLCD.gText( 0, 210, 0xffff, myLCD.WhoAmI()); 

  myLCD.setTouch(true);  // activate Touch
  
  // Button Stop
  bStop.define( 0, 0, 79, 59, "Stop", myLCD.rgb16(0xff, 0xff, 0xff), myLCD.rgb16(0x00, 0xff, 0x00), myLCD.rgb16(0x88, 0x00, 0xff), 9);
  bStop.enable(true);
  bStop.draw();
  // Button Set Time
  bSetTime.define( 80, 0, 79, 59, "Set Time", myLCD.rgb16(0xff, 0xff, 0xff), myLCD.rgb16(0x00, 0xff, 0x00), myLCD.rgb16(0x88, 0x00, 0xff), 9);
  bSetTime.enable(true);
  bSetTime.draw();

 setSyncProvider(RTC.get);   // the function to get the time from the RTC
      if(timeStatus()!= timeSet) 
         Serial.println("Unable to sync with the RTC");
      else
         Serial.println("RTC has set the system time");
  delay(10); 

}

uint8_t c;

void loop() {
  
  

  c=myLCD.getTouchActivity();
  myGetTime(); // shows actual Time
  
  
  if (c>0) {
     
    myLCD.getTouchXY(x, y);

    // quit
    if (bStop.check()) {
      myLCD.off();
      while(true);
    }
    
    // if buttonSetTime is pressed set the Time
    if ( bSetTime.check()) {
      mySetTime(); 
    }
 
  }
 
  
}


void myGetTime(){
        
      String strTime = "Zeit: "; //my TimeString

      if(hour() < 10)            // hour with leading 0 if < 10
        strTime += "0";
      strTime += hour();
      strTime += ":";
      if(minute() < 10)         // minute with leading 0 if < 10
        strTime += "0";
      strTime += minute();
      strTime += ":";
      if(second() < 10)          // second with leading 0 if < 10
        strTime += "0";
      strTime += second();
      
      strTime += " ";          // Leerzeichen als Abstandhalter zum Datum
      if(day() < 10)           //day with leading 0 if < 10
        strTime += "0";
      strTime += day();
      strTime += ".";
      if(month() < 10)          //month with leading 0 if < 10
        strTime += "0";
      strTime += month();
      strTime += ".";
      strTime += year();      //year
      
      Serial.println(strTime); //print to serial


  //  uint8_t gText(uint16_t x, uint16_t y, uint16_t colour, String s);    // Draw ‚String 53hex
      myLCD.setFont(0);
      myLCD.setFontSolid(true);
      myLCD.gText( 10, 220, 0xffff, strTime ); // print to  4D Display
}



void mySetTime(){
  setTime(15, 42, 0, 28, 11, 2011); // set Time to 15:42:00 28.11.2011
}

And know when I reset the Arduino board and I have the

setSyncProvider(RTC.get);   // the function to get the time from the RTC
      if(timeStatus()!= timeSet) 
         Serial.println("Unable to sync with the RTC");
      else
         Serial.println("RTC has set the system time");
  delay(10);

in the Setup {} the time is reset to 00:00:00 31.12.1999 and when

setSyncProvider(RTC.get);   // the function to get the time from the RTC
      if(timeStatus()!= timeSet) 
         Serial.println("Unable to sync with the RTC");
      else
         Serial.println("RTC has set the system time");
  delay(10);

is not in the Setup{} the RTC is reset to 00:00:00 1.1.1970

I hope the description is clearer know.

And now I will try the hint of James C4S to call the RTC.set();

Stefan

Hey guys I solved the problem.

The wiring was faulty. I connected the SDA/SCL to Digital 4/5 instead of Analog 4/5. And the RTC.set(time); was missing to.

Now it works fine.

Anyway thank you for your advices.

Stefan