RTC Module Not Updating Time from Computer - Please Help !

Hi everyone !

Ive been having this problem on and off for MONTHS !!!

One day my sketch will work and other days it wont update the RTC Module and all i get is:

1/1/2000-0:0:80
week: 1
1/1/2000-0:0:80
week: 1
1/1/2000-0:0:80
week: 1
1/1/2000-0:0:80
week: 1

and this repeats on and on !

Ive checked the connections, battery power is always 4v or slightly above, bought the module from here:

and have 7 of these but im on a quest for better accuracy clock crystals and just soldered a very high accuracy clock crystal to one of my RTC Modules but now tearing my hair out because i cant set the correct time and date on ANY of them !!!

From RTC Module To Arduino Hardware
BLACK (GND) To GND Pin
RED (VCC) To 5v Pin
(SDA) To A4 Pin (Analog Pin A4)
(SCL) To A5 Pin (Analog Pin A5)

This is my sketch im using and has worked fine on all others, when it wants to, but now the sketch doesnt work and after ive had-enough of trying endlessly for HOURS i leave it all alone, battery taken out and try it a few days later and it works ! But now its been 4 days and im still none the wiser sifting through endless forum posts that never mention this problem !

Does anyone know why this is happening please ?

sorry, heres the sketch:

#include <Wire.h>
  uint8_t seconds = 30;//Initialization time
  uint8_t minutes = 43;
  uint8_t hours = 14;
  uint8_t week = 4;
  uint8_t days = 16;
  uint8_t months = 8;
  uint16_t Year = 12;
int bcd2bin(int temp)//BCD  to decimal
{
	int a,b,c;
	a=temp;
	b=0;
	if(a>=16)
	{
		while(a>=16)
		{
			a=a-16;
			b=b+10;
			c=a+b;
			temp=c;
		}
	}
	return temp;
}

int bin_to_bcd(int temp)//decimal to BCD
{
	int a,b,c;
	a=temp;
	b=0;
	if(a>=10)
	{
		while(a>=10)
		{
			a=a-10;
			b=b+16;
			c=a+b;
			temp=c;
		}
	}
	return temp;
}
void setup () {
    Serial.begin(9600);
    Wire.begin();
    //begin(void) {return 1;}
}
 
void loop () {
  /*Wire.beginTransmission(0x68);//DS1307 write the initial time
  Wire.write(0);
  Wire.requestFrom(0x68, 7);
  Wire.write(bin_to_bcd(seconds));
  Wire.write(bin_to_bcd(minutes));
  Wire.write(bin_to_bcd(hours));
  Wire.write(bin_to_bcd(week));
  Wire.write(bin_to_bcd(days));
  Wire.write(bin_to_bcd(months));
  Wire.write(bin_to_bcd(Year));	
  Wire.endTransmission();*/
  
  while(1){
  Wire.beginTransmission(0x68);//Send the address of DS1307
  Wire.write(0);//Sending address	
  Wire.endTransmission();//The end of the IIC communication
  
  Wire.requestFrom(0x68, 7);//IIC communication is started, you can continue to access another address (address auto increase) and the number of visits
    seconds = bcd2bin(Wire.read());//read time
    minutes = bcd2bin(Wire.read());
    hours = bcd2bin(Wire.read());
    week = Wire.read();
    days = bcd2bin(Wire.read());
    months = bcd2bin(Wire.read());
    Year = bcd2bin(Wire.read()) + 2000;
   
      Serial.print(days, DEC);
      Serial.print('/');
      Serial.print(months, DEC);
      Serial.print('/');
      Serial.print(Year, DEC);//Serial display time
      Serial.print('-');
      Serial.print(hours, DEC);
      Serial.print(':');
      Serial.print(minutes, DEC);
      Serial.print(':');
      Serial.print(seconds, DEC);
      Serial.println();
      Serial.print(" week: ");
      Serial.print(week, DEC);
      Serial.println();
      delay(1000);
  }
}

This sketch "normally" grabs the date and time from my computer and updates the RTC module with it MINUS 12 seconds it takes to upload the sketch so to get it uploaded accurately to the second, i wait till theres 12 seconds left in the minute on my computer's clock, then hit the upload button and usually only a second or two in or out !

Would anyone be able to shed any light on this please please please ?!?

A GREAT Many thanks in advance for any help towards a remedy !

The code in this comment isn't right:

  /*Wire.beginTransmission(0x68);//DS1307 write the initial time
  Wire.write(0);
  Wire.requestFrom(0x68, 7);
  Wire.write(bin_to_bcd(seconds));
  Wire.write(bin_to_bcd(minutes));
  ...

The requestFrom initiates a read operation. If you use this to set the initial date/time, it isn't going to work properly. Remove the requestFrom statement.

Pete

Hey thanks, took the whole statement out, its updated with the set time and date in the sketch but the RTC module still doesnt count the time or 'tick' !

heres what i get:

16/8/12-14:43:30
week: 4
16/8/12-14:43:30
week: 4
16/8/12-14:43:30
week: 4
16/8/12-14:43:30

Any idea's ?!?

Maybe you need to see this post [SOLVED] How to set time on DS1307 using Time library? - Programming Questions - Arduino Forum

I have the same module and also I bought this the last month and I just get them (only 2) I try tis tutorial http://bildr.org/2011/03/ds1307-arduino/ that is also in the post that I mention.

I just wanted to try it out, here is the result:

DS1307RTC Read Test
-------------------
Ok, Time = 11:19:28, Date (D/M/Y) = 25/6/2013
Ok, Time = 11:19:29, Date (D/M/Y) = 25/6/2013
Ok, Time = 11:19:30, Date (D/M/Y) = 25/6/2013
Ok, Time = 11:19:31, Date (D/M/Y) = 25/6/2013
Ok, Time = 11:19:32, Date (D/M/Y) = 25/6/2013
Ok, Time = 11:19:33, Date (D/M/Y) = 25/6/2013
Ok, Time = 11:19:34, Date (D/M/Y) = 25/6/2013
Ok, Time = 11:19:35, Date (D/M/Y) = 25/6/2013
Ok, Time = 11:19:36, Date (D/M/Y) = 25/6/2013
Ok, Time = 11:19:37, Date (D/M/Y) = 25/6/2013
Ok, Time = 11:19:38, Date (D/M/Y) = 25/6/2013

the sketch: DS1307RTC Library, For Accessing Real Time Clock (RTC) Chips

#include <DS1307RTC.h>
#include <Time.h>
#include <Wire.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);
}

first time that i touch them, but with this code references i will make a clock for my desktop