RTC DS1307 Backup battery

Dear Rogers,
Thanks for the reply

I identified a problem with my I2CRead() subroutine, but it is working. please see below I2C Read() subroutine

Code:
void I2Cread(){
		for(i=0;i<8;i++){
        I2CStart();
		I2CSend(0xD0);							/* Send slave address with write */ /* Send address for dummy write operation *//* this address is actually where we are going to read from */					       						       
        I2CSend(0x00);							/* Send a repeated start, after a dummy write to start reading */
        I2CRestart();
        I2CSend(0xD1);							/* send slave address with read bit set */
 
			
      			I2CData[i] = I2CRead();			/* read a byte */								/* ACK if its not the last byte to read */             	 
 
        }
		 	I2CStop();							/* Send stop */
}

In the above code the FOR loop is placing in wrong place, but it is working

and see below codes. I put for loop in correct location,but it does not working
Code:
void I2Cread(){
		
        I2CStart();
		I2CSend(0xD0);							/* Send slave address with write */ /* Send address for dummy write operation *//* this address is actually where we are going to read from */					       						       
        I2CSend(0x00);							/* Send a repeated start, after a dummy write to start reading */
        I2CRestart();
        I2CSend(0xD1);							/* send slave address with read bit set */
 
				for(i=0;i<8;i++) {
      			I2CData[i] = I2CRead();			/* read a byte */								/* ACK if its not the last byte to read */             	 
 
        }
		 	I2CStop();							/* Send stop */
}

Please advice
Thanks in advance
 
Last edited:
I did that for you a few posts back.... The read function MUST reply to the DS1307 If you send an ACK the data will keep comming... You send a NACK to stop reading SEE POST #7

Code:
void I2Cread()
	{
        I2CStart();
		I2CSend(0xD0); /* Send slave address with write */ /* Send address for dummy write operation *//* this address is actually where we are going to read from */					       						       
        I2CSend(0x00); /* Send a repeated start, after a dummy write to start reading */
        I2CRestart();
        I2CSend(0xD1); /* send slave address with read bit set */
 
		for(i=0;i<7;i++) 
			{
      			I2CData[i] = I2CRead(); /* read a byte */ /* ACK if its not the last byte to read */             	 
 				I2CAck();
        	}
		I2CData[i] = I2CRead();	
		I2CNak();
	 	I2CStop(); /* Send stop */
	}

This works
 
Dear Rogers,

My next step is to add three switch to the cct for adjust the time. Therefore I added three micro switch to PORTB pin 4,5,6 and ground each via 47Ω resister. Could you please advice nest steps

Thanks in advance
 
Last edited:
47Ω resister

5 / 47 = 100mA No no no... Micro's can't source that.... Try 470Ω +.. It will survive better.

The next step is to write a key read function that will read, debounce and acknowledge a key press...
 
Hi guys I have the same problem.... When Mains power is removed ..... & given back again , the time gets resetted... So please help me............
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…