View previous topic :: View next topic |
Author |
Message |
padbol
Joined: 25 Apr 2011 Posts: 11 Location: Belgium
|
DS1307, turning crystal on |
Posted: Thu May 31, 2012 6:04 am |
|
|
Hello,
I'm experiencing a weird issue with my RTC which seems to not start the oscillator after a powering down.
I'm using the initialisation source code provided below that I found here : http://www.ccsinfo.com/forum/viewtopic.php?t=23255
Code: |
void ds1307_init(void)
{
BYTE seconds = 0;
i2c_start();
i2c_write(0xD0); // WR to RTC
i2c_write(0x00); // REG 0
i2c_start();
i2c_write(0xD1); // RD from RTC
seconds = bcd2bin(i2c_read(0)); // Read current "seconds" in DS1307
i2c_stop();
seconds &= 0x7F;
delay_us(3);
i2c_start();
i2c_write(0xD0); // WR to RTC
i2c_write(0x00); // REG 0
i2c_write(bin2bcd(seconds)); // Start oscillator with current "seconds value
i2c_start();
i2c_write(0xD0); // WR to RTC
i2c_write(0x07); // Control Register
i2c_write(0x80); // Disable squarewave output pin
i2c_stop();
}
|
When I'm turning power on, this function is called to initiate RTC. Time is displayed on a LCD which always shows 00:00:00
If I set a date OR a time, oscillator starts and time begins to run to 00:00:01 ; 00:00:02 ; ...
Does someone can help me about that problem? Using "seconds & 0x7F", oscillator should start. Isn't it?
Please note that I'm trying it without any battery. Could it be a part of the problem? _________________ - Be the change you want to see in the world (Gandhi) - |
|
|
drh
Joined: 12 Jul 2004 Posts: 192 Location: Hemet, California USA
|
|
Posted: Thu May 31, 2012 8:50 am |
|
|
If you remove power without a battery attached, the oscillator will stop. _________________ David |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Thu May 31, 2012 9:47 am |
|
|
Hi,
Search the forum, there are many threads on this subject. Summary: you need the battery....
John |
|
|
|