Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

My RTC is ds1307 not work

Status
Not open for further replies.
Dear Alex,
Thanks for reply
No idea how may I check bit 7 , In debugging or ????
Please advice

Thanks
 

Create a char variable and assign the content of address 0 to it , then just check the value of bit 7

If you have already stored the read content of address 0 in an array like I2CData[0] in your code then check that

If you want use if (!(I2CData[0] & (1<<7))) ... this will be true is bit 7 is 0

- - - Updated - - -

An quick test alternative is to just write 0x00 to address 0 of ds1307 , this would set the bit7 to 0 and it should start giving time result
 
  • Like
Reactions: PA3040

    PA3040

    Points: 2
    Helpful Answer Positive Rating
Dear Alex,
Thanks for reply

This is my I2C write sub routine
This subroutine write the value of array to the RTC
Can you please guide me where to the insert the syntax you provided above

Code:
void I2Cwrite(){

					/* Initialize I2C Port */
        I2CStart();				/* Send Start condition */
        I2CSend(0xD0);			/* Send DS1307 slave address */
        I2CSend(0x00);						
			for(i=0;i<8;i++) {				/* Loop to write 8 bytes */
                           I2CSend(I2CInitval[i]);	
               							
        }
			I2CStop();	
}

Thanks in advance
 
Last edited:

This is the write sequence , if you are already writing 0 to 0x0 then the bit 7 is for sure 0 , there is no point to check it and it shouldn't be the cause of the problem.


What I meant was to read address 0

Code:
I2Cstart();
I2CSend(0xD1);
I2CAck();
I2CData[0]=I2CRead();
I2CNak();
I2CStop();

if (!(I2CData[0] & (1<<7))).....  // true if bit7 is 0
 

Dear Alex,
Thank you so much for continuous help

I change my I2C read subroutine as follows, in this subroutine the reading address change by for loop variable
but as per datasheet if we read 00 location it is increasing automatically for 01 location

Code:
void I2Cread(){
		for(i=0;i<8;i++){
        I2CStart();
		I2CSend(0xD0);											       						       
        I2CSend(i);							
        I2CRestart();
        I2CSend(0xD1);							

			         				
      			I2CData[i] = I2CRead();			/* read a byte */

                								/* ACK if its not the last byte to read */             
        }
		 I2CStop();								/* Send stop */
}

As per above my RTC is working fine
 

I don't understand what you are doing in your code, you set the device to write, send the address and then stop writing and start reading...and you execute all that 8 times (inside the loop)

The sequence to read all regs would be

Code:
I2CStart();
I2CSend(0xD1);
I2CAck();
I2CSend(0);

for(i=0; i<8; i++) {
    I2CAck();
    I2CData[i]=I2CRead();
}

I2CNak();
I2CStop(); /* Send stop */

- - - Updated - - -

OK, that doesn't set the address pointer so there is a need for a write before that but only once outside of the loop

- - - Updated - - -

Code:
I2CStart();
I2CSend(0xD0); // write mode
I2CAck();
I2CSend(0);		// set address pointer to 0
I2CRestart();

I2CSend(0xD1); 	// read mode

for(i=0; i<8; i++) {  // read the registers
    I2CAck();
    I2CData[i]=I2CRead();
}

I2CNak();
I2CStop(); /* Send stop */
 
  • Like
Reactions: PA3040

    PA3040

    Points: 2
    Helpful Answer Positive Rating
Dear alex,
Thanks for reply

Actually I set the address pointer (I2CSend(0)); but it is reading 0 location only which is second and if I set address pointer as (I2CSend (1) Then It is reading only location 1 which is minute. Therefore I put all read loop under for loop and address pointer changed as I2CSend(i); i is for loop variable then it is working fine
please advice if you have free times, sorry for disturbing to you continuously

Thanks in advance
 

For the first time power-up DS1307, all the reading will become 0 and the second not running. We need to give value to second first, then it will running.
 
  • Like
Reactions: PA3040

    PA3040

    Points: 2
    Helpful Answer Positive Rating
Dear Engshahrul,
Thanks for reply
Actually I would set address pointer but the thing is, it is reading only the location what we painted and it does not increment automatically
Could you please advice
Thanks in advance
 

For sure, the address not increments automatically. So, need to read to specific address like this
Code:
sec=rtc_get(0); //get sec
min=rtc_get(1); //get min
hrs=rtc_get(2); //get hours
day=rtc_get(3); //get day
date=rtc_get(4); //get date
month=rtc_get(5); //get month
year=rtc_get(6); //get year
 
  • Like
Reactions: PA3040

    PA3040

    Points: 2
    Helpful Answer Positive Rating
Dear alex,
Thanks for reply

Actually I set the address pointer (I2CSend(0)); but it is reading 0 location only which is second and if I set address pointer as (I2CSend (1) Then It is reading only location 1 which is minute. Therefore I put all read loop under for loop and address pointer changed as I2CSend(i); i is for loop variable then it is working fine

So you mean that

Code:
I2CStart();
I2CSend(0xD0); // write mode
I2CAck();
I2CSend(0);		// set address pointer to 0
I2CRestart();

I2CSend(0xD1); 	// read mode

for(i=0; i<8; i++) {  // read the registers
    I2CAck();
    I2CData[i]=I2CRead();
}

I2CNak();
I2CStop(); /* Send stop */

reads only address 0?
what values do you get in I2CData[1] to I2CData[7]?
 
  • Like
Reactions: PA3040

    PA3040

    Points: 2
    Helpful Answer Positive Rating
Dear alex,

The values from I2CData [1] to I2Cdata [7] ?? ?? but only I2CData[0] = seconds and and update nicely

Dear alex as per your example code in the post number 32, it does not increment address pointer by codes and it is increasing address pointer automatically in side the DS1307 as per codes

any helps

- - - Updated - - -

Dear Engshahrul,
Thanks for reply

As per your codes it is increasing address pointer by codes but as i know the datasheet says the address pointer increase automatically after read one location

please advice
 

Dear alex,

The values from I2CData [1] to I2Cdata [7] ?? ?? but only I2CData[0] = seconds and and update nicely

Dear alex as per your example code in the post number 32, it does not increment address pointer by codes and it is increasing address pointer automatically in side the DS1307 as per codes

any helps

I have used the following function in the past that returns results fine

Code:
tw_start();
tw_write_data(0xd0);
tw_write_data(0);
tw_start();
tw_write_data(0xd1);
*sec=bcd2bin(tw_read(1));
*min=bcd2bin(tw_read(1));
*hour=bcd2bin(tw_read(0));
tw_stop();

The sequence is the same as I gave you in the previous post , the only difference is the use of start instead of restart, I'm not sure what your restart does so use start instead.

try

Code:
I2CStart();
I2CSend(0xD0); // write mode
I2CAck();
I2CSend(0);		// set address pointer to 0
[COLOR="#FF0000"]I2CStart();  // use start instead of restart[/COLOR]

I2CSend(0xD1); 	// read mode

for(i=0; i<8; i++) {  // read the registers
    I2CAck();
    I2CData[i]=I2CRead();
}

I2CNak();
I2CStop(); /* Send stop */

The address increments automatically between reads, you don't have to set the address pinter 8 times
 
  • Like
Reactions: PA3040

    PA3040

    Points: 2
    Helpful Answer Positive Rating
Dear All
My RTC reader is working with some improvements and with some issues

step1:The second digit increments up to 60 and rest 00 while incrementing minute
step2: The minutes digit increments up to 60 and rest 00 while incrementing Hour
step3: Hour digit is incrementing But it dose not rest to 0
In the proteus it is working well
Please advice
 

Dear All
step3: Hour digit is incrementing But it dose not rest to 0

What do you mean?
How did you test it and what result did you get?
You can either set it to 12 or 24 hour operation and after that the hour counter will restart from 1 or 0.
Which mode did you use 12 or 24 hour?
 
  • Like
Reactions: PA3040

    PA3040

    Points: 2
    Helpful Answer Positive Rating
Dear Alex,
This is my I2Cwrite subroutine
Can you please advice how may i set the 12 and 24 setting in the I2C subroutine

Code:
void I2Cwrite(){
											
 		I2CStart();						
        I2CSend(0xD0);					
        I2CSend(0x00);						
			for(i=0;i<8;i++) {			
            	I2CSend(I2CInitval[i]);									
        }
			I2CStop();						
}

Thanks in advance
 

It's the register in location 02h

The DS1307 can be run in either 12-hour or 24-hour mode. Bit 6 of the hours register is defined as the 12-hour or
24-hour mode-select bit. When high, the 12-hour mode is selected. In the 12-hour mode, bit 5 is the AM/PM bit with
logic high being PM. In the 24-hour mode, bit 5 is the second 10-hour bit (20 to 23 hours). The hours value must be
re-entered whenever the 12/24-hour mode bit is changed.

You can set it using your hour (I2CInitval[2]) value bit 6, I'm not sure what mode you are currently using
 

Dear Alex
I did it as follows
But problem remaining unchanged

Code:
void I2Cinitval(){
		I2CStart();						
        I2CSend(0xD0);					
        I2CSend(0x02);
		I2CSend(0x40);
		I2CStop();						
}
 

You didn't use the I2CAck() after each send.

What exactly is the problem , you haven't specified what is wrong, all you said is "Hour digit is incrementing But it dose not rest to 0"
 
  • Like
Reactions: PA3040

    PA3040

    Points: 2
    Helpful Answer Positive Rating
Dear Alex
Thanks for reply
I did not use I2CAck because it become mess when inset I2CAck
Still Hour digit incrementing continuously I mean if we set 12 mode but it is incrementing 13,14,15,....
when we set 24 mode but it is incrementing 25,26,27....
I think I did not set the 12 or 24 mode, did it?
Please advice
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top