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.

How to write to DS1307 ?

Status
Not open for further replies.

bianchi77

Advanced Member level 4
Joined
Jun 11, 2009
Messages
1,313
Helped
21
Reputation
44
Reaction score
20
Trophy points
1,318
Location
California
Activity points
9,442
Friends,

I tried to write to DS1307, but it's not writing properly,

I tried to write 16:01:00 Sunday,2 June 2013
but the result is
15:05:36 Sun 10 Mon 2051,

What do I miss here ?

thanks
Code:
void Write_DS1307(void)
{
	unsigned char i, hour_format;

	// Make sure we enable the Oscillator control bit CH=0 on Register 0x00
	ds1307_addr[0]=ds1307_addr[0] & 0x7F;

	// Start the I2C Write Transmission
	i2c_start(DS1307_ID,DS1307_ADDR,TW_WRITE);

	// Start from Address 0x00
	i2c_write(0x00);
   
	// Write the data to the DS1307 address start at 0x00
	// DS1307 automatically will increase the Address.
	
	ds1307_addr[0] = '0';
	i2c_write(dec2bcd(ds1307_addr[0]));//second
    _delay_ms(10);
    ds1307_addr[1] = '1';
    i2c_write(dec2bcd(ds1307_addr[1]));//minute
	_delay_ms(10);
	ds1307_addr[2] = '16';
	i2c_write(dec2bcd(ds1307_addr[2]));//hour
	_delay_ms(10);
	ds1307_addr[3] = '0';
	i2c_write(dec2bcd(ds1307_addr[3]));//day of the week
    _delay_ms(10);
    ds1307_addr[4] = '2';
    i2c_write(dec2bcd(ds1307_addr[4]));//day of the month
    _delay_ms(10);
    ds1307_addr[5] = '6';
    i2c_write(dec2bcd(ds1307_addr[5]));//month
    _delay_ms(10);
    ds1307_addr[6] = '13';
    i2c_write(dec2bcd(ds1307_addr[6]));//year
}
 

hello,

are you using C18 ?

for the year
you put caractere '13' ;
use
ds1307_addr[6] = 13;


check also if radix=decimal or hexadecimal

or don't use Dec2bcd()
and write directly the value 0x13 in the register ...

i2c_write(ds1307_addr[6]);//year
 
Last edited:

hello,

are you using C18 ?

for the year
you put caractere '13' ;
use
ds1307_addr[6] = 13;


check also if radix=decimal or hexadecimal

or don't use Dec2bcd()
and write directly the value 0x13 in the register ...

i2c_write(ds1307_addr[6]);//year
Thanks mate, I'll try and let you know

- - - Updated - - -

You are right mate, thank you very much :)
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top