Updating bit 6 on address 02 on DS1307 ?

Go To Last Post
7 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Guys,

Does anyone know on updating bit 6 on address 02 on DS1307 ?
Is it directly write like this ?
i2c_write(ds1307_addr[2]);//hour

I'm confused on changing bit 6

can it be only ds1307_addr[2]=0x40 ?

Any concerns will be appreciated,
thank you

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You have to do a read-modify-write. i.e. read the current hour, OR it with 0x40 and write it back.

i2c_start(0xD0);
i2c_write(0x02);        //select hour register
i2c_repstart(0xD1);
hour = i2c_readNak();   //read it
i2c_repstart(0xD0);
i2c_write(0x02);        //select hour register
i2c_write(hour | 0x40); //write to it
i2c_stop();

Untested. It is your job to read your library documentation and the DS1307 data sheet.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ok thanks for your suggestion...
can I do it in hard code ? I want to write 22:00
looks like it's not working when I did :

ds1307_addr[2]++;
if (ds1307_addr[2] >= 24)
{
ds1307_addr[2] = 0;

}

ds1307_addr[2] = 0x22;
Write_DS1307();//hour
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Here's a good tutorial with code:

http://extremeelectronics.co.in/...

I used that site (and the datasheet, of course) to program a clock using the ds1307

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I got it :

ds1307_addr[2] = 0x22;
	i2c_write(ds1307_addr[2]);//hour

Thanks for helping

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

bianchi77 wrote:

ds1307_addr[2]++;
if (ds1307_addr[2] >= 24)
{
ds1307_addr[2] = 0;

}

ds1307_addr[2] = 0x22;
Write_DS1307();//hour

Without having looked at the DS1307 datasheet, i'm wondering why you are comparing against a decimal 24 in the hours field, but then try to set it to a value of hex 22 for 22:00?

Einstein was right: "Two things are unlimited: the universe and the human stupidity. But i'm not quite sure about the former..."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

No, I have not looked at the "ExtremeElectronics" code.

I am guessing that it reads all 8 'time' registers into an array.
You can manipulate the array. Then write back to all 8 registers.

Note that this could go wrong if you happen to write back when registers have just updated. e.g. 23:59:59

In practice, you set all the registers to the current time and format as a one-off. And never write again.

David.