Go Down

Topic: DS1307 won't set if already set (Read 2 times) previous topic - next topic

hardcore

Digging about on this  Start / Stop issue
I have found one library (DS1307 Arduino Library) for the DS1307 & Arduino
http://code.google.com/p/ds1307new/downloads/list

That actually physically STOPS the clock!!  killing the oscillator by setting bit 7 in register 0
The only reason to do this would be for power saving, if the clock is NOT needed,  all other libraries read/write to the clock without having this functionality.

I'm going to dig about in my stock room for an DS1307 clock module and see if we can settle this once and for all, just incase the data sheet is wrong.


floresta

It looks like I opened a can of worms.

Don


retrolefty


It looks like I opened a can of worms.

Don




Not at all. At this forum we like this kind of activity. The biggest problem in my opinion is when a technical question or topic like this is finally resolved to everyone's satisfaction (and it usually does get resolved), we don't seem to have a good way to archive the information away in a matter that's easily retrieved by newcomers at a later date.

Lefty

floresta

Reply #15 brought up a pet peeve of mine:
Quote
I have found one library (DS1307 Arduino Library) for the DS1307 & Arduino
http://code.google.com/p/ds1307new/downloads/list


Just what we need - another "new" library.  What are they going to call the next one, Newest, Return of New, Very Newest?  

The best ambiguous choice would be 'Latest'. I have two sets of paper maps from the same publisher with that title, purchased two or three years apart (in the 70s).


Grumpy Don

retrolefty


Reply #15 brought up a pet peeve of mine:
Quote
I have found one library (DS1307 Arduino Library) for the DS1307 & Arduino
http://code.google.com/p/ds1307new/downloads/list


Just what we need - another "new" library.  What are they going to call the next one, Newest, Return of New, Very Newest?  

The best ambiguous choice would be 'Latest'. I have two sets of paper maps from the same publisher with that title, purchased two or three years apart (in the 70s).


Grumpy Don


Unfortunately the major API changes that the Arduino development team created with the release of the Arduino V1.0 has cause the need for a whole lot of user contributed libraries to be in need of tweaking to be able to compile in 1.0. As there was never an 'official' arduino RTC library it's not surprising there are so many different ones out in the wild. Such is life in a wide open arduino world.  ;)

floresta

#20
Feb 15, 2012, 03:02 am Last Edit: Feb 15, 2012, 03:05 am by floresta Reason: 1
I have no complaints about the emergence of new libraries that improve upon and/or replace older ones.  

The problem is when you improve a library called, for example, the XyzzyLibrary and you name the improved version 'NewXyzzyLibrary'.  What do you call the next iteration?

Don

retrolefty


I have no complaints about the emergence of new libraries that improve upon and/or replace older ones.  

The problem is when you improve a library called, for example, the XyzzyLibrary and you name the improved version 'NewXyzzyLibrary'.  What do you call the next iteration?

Don


I hear what what you are saying. My point is to just point out the any and all 3rd party libraries go through no kind of 'official' vetting, approval, official naming, or even review. They are at best just allowed to be parked in the playground section along with many other related libraries. The user contributed library part of the Arduino world is both it's greatest strength and greatest weakness. On the one hand there is a tremendous amount of 3rd party code avalible, but on the other hand it may not even work due to changes in the IDE over time.

Only when the Arduino developers group allow a specific library to become part of the official IDE distribution does a library have a chance to be cared and feed properly to keep up with IDE and new boards as they are released.

So a more basic question for the purpose of this posted thread might be, why is there not an 'official' DS1307 library distributed with the IDE? It's not like it's not the most common RTC used in the arduino world?

Lefty

Dane




You are misunderstanding the 'meaning' of start & stop


Who is? If it's me, I'd like to know.


This is NOT you.
Quote
The DS1307 must be stopped to set new time and data values, and then restarted.


Obviously  'DANE' (that is you) you do not fully read the thread of the questions you ask.

For the record (possibly *not* including DANE, unless he changed his mind)  to anyone saying the  DS1307 needs to be 'stopped'


Thanks, hardcore. Not for your rude and incorrect assertion but for your being so kind as to clarify your remark.

floresta

Quote
... but for your being so kind as to clarify your remark.


The only reason he had to clarify his remark is because he is the one who introduced the red herring.  In my opinion he is the one who did not fully understand "the thread of the question" we were discussing.  It was obvious, before he started talking about Start and Stop encapsulation etc., that we were discussing the internal workings of the clock chip itself and not the I2C implementation.  

He quotes "the data sheet" but I have no idea what data sheet he is referring to.  I can't find the phrases he quotes in my Maxim DS1307 data sheet.  In my data sheet I found one place where the term 'I2C START' is used in conjunction with reference to the buffers, but that was referring to reading, not writing.


Now, for the benefit of future Googlers, let me summarize the first two entries in this thread.

   The original post questioned why, when using the sketch provided by ladyada, one cannot set a clock that is already running.

   The second post gave the answer.  It has nothing to do with the clock chip, it is because that particular sketch was written to perform in that manner.


Don

hardcore


Quote
... but for your being so kind as to clarify your remark.


The only reason he had to clarify his remark is because he is the one who introduced the red herring.  In my opinion he is the one who did not fully understand "the thread of the question" we were discussing.  It was obvious, before he started talking about Start and Stop encapsulation etc., that we were discussing the internal workings of the clock chip itself and not the I2C implementation.  

He quotes "the data sheet" but I have no idea what data sheet he is referring to.  I can't find the phrases he quotes in my Maxim DS1307 data sheet.  In my data sheet I found one place where the term 'I2C START' is used in conjunction with reference to the buffers, but that was referring to reading, not writing.


Now, for the benefit of future Googlers, let me summarize the first two entries in this thread.

   The original post questioned why, when using the sketch provided by ladyada, one cannot set a clock that is already running.

   The second post gave the answer.  It has nothing to do with the clock chip, it is because that particular sketch was written to perform in that manner.


Don


Personally,  'Don'  I that you need to read the thread, before spouting off and 'warning' others about posts.


Has anyone else experienced that the DS1307 won't set if it already has the time? I'm using the ladyada library which includes a sketch to set the time using system time from the point of compiling (which means the time is out by about 15s). I've found that the time won't adjust if I've already set it and I have to remove the battery to set the time again! Seems very odd…

The fact that it will set if I remove the battery seems to rule out any sketch or connections issues?




The DS1307 must be stopped to set new time and data values, and then restarted. Most (all?) DS1307 libraries will have those commands avalible for use. No need to pull the battery. Note this fragment section from my RTC sketch for setting the time and data, note it first issues a RTC.stop() command, then sets the data values and ends with a RTC.start() command. Note that if a DS1307 (if it has a functioning back-up battery) is powered off while it was running, it will automatically return to the running mode when powered back up.

Code: [Select]

 RTC.stop();                          // chip must be stopped before sending new values
 RTC.set(DS1307_SEC,0);        //set the seconds
 RTC.set(DS1307_MIN,28);       //set the minutes
 RTC.set(DS1307_HR,23);        //set the hours   note 24 hour clock
 RTC.set(DS1307_DOW,5);        //set the day of the week
 RTC.set(DS1307_DATE,13);      //set the date
 RTC.set(DS1307_MTH,1);        //set the month
 RTC.set(DS1307_YR,11);         //set the year  
 RTC.start();                          // chip must be started for RTC to run


Lefty


The first post clearly includes the sentence
"Has anyone else experienced that the DS1307 won't set if it already has the time?" then goes on to state the library being use is lady ada's

The second post clearly states the need to call RTC.stop() this post is not a 'red-herring', it is in the forum for all to see, nor does it mention anything about  Lady ada, in fact if you knew anything about the lady ada library you would know that there in not even an RTS.stop() function, which would indicate we are obviously NOT talking about the lady ada library and the thread has moved on, albeit without your permission, but moved on it has.

Finally take a look at the title of the post.
"DS1307 won't set if already set", nope I don't see anything about a reference specifically to the lady ada library(granted the initial poster may have overlooked it, but by default the thread is now open to discuss ALL aspects of "DS1307 won't set if already set").

In my following post, hopefully the issue will be settled once and for all, irrelevant of the library used.



hardcore

#25
Feb 16, 2012, 08:28 am Last Edit: Feb 16, 2012, 01:57 pm by hardcore Reason: 1
Enclosed is a fully tested sketch for the arduino uno, though it should work on other platforms with suitable connection adjustments.

The sketch allows the DS1307 registers to be set with an initial time.

At any time you may use the serial console to test the chip:

h Halt the internal DS1307 oscillator, keeping the current time intact
s Start the internal DS1307 oscillator,
r reset the DS1307 with the initial time

The above can be used in any sequence, you can for example re-set the time on the DS1307 chip whilst it is running,
or you can stop the oscillator and set the time.
*Note:  
1. Rightly or wrongly some script/libraries prevent the DS1307 chip from being reset once it has been initially set, this is NOTHING to do with chip functionality, but supposedly there to prevent the RTC from being corrupted on sketch startup.
2. Some sketches just DO NOT work, mainly because of issues in the wire.h library that have since been corrected for >= DE 1.0

Dane



The sketch allows the DS1307 registers to be set with [a] time.

At any time you may use the serial console to test the chip:

h Halt the internal DS1307 oscillator, keeping the current time intact
s Start the internal DS1307 oscillator,
r reset the DS1307 with the initial time



If I'm not very much mistaken, Mr. Hardcore, what you've posted is effectively a working version of the below (amongst other things, i.e. your proof of debunk)?


[It] needs some tweeking to work on IDE 1.0. You just change the time and data values in the setup statements and upload to the board. The board will wait until you send a character from the serial monitor and then sets the RTC [...].

Code: [Select]

//Sets and reads the time and date values from a Real Time Clock (RTC) DS1307 and displays it in the serial monitor

Lefty

hardcore

#27
Feb 16, 2012, 02:04 pm Last Edit: Feb 16, 2012, 02:32 pm by hardcore Reason: 1



If I'm not very much mistaken, Mr. Hardcore, what you've posted is effectively a working version of the below (amongst other things, i.e. your proof of debunk)?


[It] needs some tweeking to work on IDE 1.0. You just change the time and data values in the setup statements and upload to the board. The board will wait until you send a character from the serial monitor and then sets the RTC [...].

Code: [Select]

//Sets and reads the time and date values from a Real Time Clock (RTC) DS1307 and displays it in the serial monitor

Lefty



Jesus....
Sometimes I just despair.......

The program I attached allows multiple TESTING functions:
1. Set a time-> then randomly RESET the time-> WITHOUT STOPPING the DS1307. (r)
2. Set a time-> then randomly STOP the DS1307 -> THEN randomly RESET the time. ->THEN randomly RESTART the DS1307 (h r s)
3. Set a time-> STOP the DS1307 -> START the DS1307  (h s)

Analysis
1. Shows that you can reset the time randomly without stopping the DS1307 oscillator.
2. Shows that the timer can be loaded and will not use the values until the DS1307 oscillator is started.
3. Shows that the DS1307 oscillator can be stopped at the current time and holds it indefinitely.

Conclusions
1. DS1307 does not need to be stopped to load time
2 Consider the situation where people keep asking how to absolutely set an accurate time:
Solution: set the time of the DS1307 in the future with the oscillator stopped, sync to external time source, at exactly the right time, START the oscillator, it is a single I2c byte write into an empty buffer, thereby reducing the wire.h library delays to a minimum.


caveats
1.The sample you refer to  ONLY STOPS the DS1307 THEN sets the time, telling us absolutely nothing about the any possible requirements of stopping the oscillator to load the values.
2 The code is partially incorrect, since it stops the oscillator writes the values then restarts the oscillator, theoretically it will always be 'slow' , since the internal counter has been stopped for the duration of the writes to the other registers, whereas NOT stopping the clock ensures that the sub-second counting continues WHILST the other registers are being loaded leading to a theoretical higher accuracy.

Code: [Select]

  RTC.stop();
  RTC.set(DS1307_SEC,0);        //set the seconds
........
  RTC.start();   



Dane

#28
Feb 16, 2012, 02:31 pm Last Edit: Feb 16, 2012, 02:35 pm by DANE Reason: 1

Jesus....
Sometimes I just despair.......
If you cannot see and understand the difference then I cannot help you.


Hardcore, you're being very silly. Suggest you take some time off somewhere warm.

I'm not interested in your "debunk". I'm interested in how I could use your code to set my RTC with the correct time by sending it a serial message.

If you read the thread properly, you'll see that.

Also, you messed up your quotes in your last delightful missive.

P.S. I would just like to add that Hardcore amended his post after I posted this.

floresta

Quote
P.S. I would just like to add that Hardcore amended his post after I posted this.


You have to be very careful about this especially when replying to a post that is obviously incorrect.  The original poster frequently goes back and fixed or removes the error and then you look like the one who is the idiot.  It also frequently negates the thread as a source of useful information in the future.

One way to deal with this is with a quote in your reply and the other is to keep a copy of the incorrect stuff so you can repost it if necessary to clear things up.


Don

Go Up