CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

DS1307, turning crystal on

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
padbol



Joined: 25 Apr 2011
Posts: 11
Location: Belgium

View user's profile Send private message

DS1307, turning crystal on
PostPosted: Thu May 31, 2012 6:04 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu May 31, 2012 8:50 am     Reply with quote

If you remove power without a battery attached, the oscillator will stop.
_________________
David
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Thu May 31, 2012 9:47 am     Reply with quote

Hi,

Search the forum, there are many threads on this subject. Summary: you need the battery....

John
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group