DS1307 problems

LED Maestro

Senior Member
Hey all,
Many months ago I asked a question about programming and reading a DS1307 RTC module and got great help and my clock working. However, after not using the circuit for at least 4 months, I find that when I come to check its still working, I get a constant square wave o/p from the RTC and when I reprogram and debug it, the mins and hours variables are stuck at 255 and the seconds keep changing from 209 to 255.
I am using this circuit as part of my final year project at college and I'm extremely upset to see it not working now.
Any advice is greatly appreciated.
P.S. I am using a Picaxe28X2, SDA and SCL have appropriate pull-up resistors, DS1307 has a new 3V battery for backup, in other words nothing has changed on the board since I last used it
 

nick12ab

Senior Member
Have you checked for shorts or broken wires?

ADDED: What are you reprogramming and debugging?
 
Last edited:

g6ejd

Senior Member
Sounds like the clock data has become corrupt. Try setting the time again and see if it then read properly. It may have received some random (or programmed!) erroneous writes. Also check the battery backup is connected as per the data sheet. Did you check the backup before? Even a few seconds of power down is enough to do that. Check that battery is OK too.
 

LED Maestro

Senior Member
Thanks to you both for your replies. Nick, I have replaced all wires on the board and its still not working. I reprogrammed the pic to read the RTC and debug so I could see what it is reading. g6ejd, I thought that the RTC might have become corrupt in some way. When I first started this project, I mistakingly had my PSU leads the wrong way round and thus fed the power into my circuit 'backwards'. This only occured for about 10 seconds before I realised my mistake however it worked fine after that. Could this have anything to do with it not working now? I have checked the Battery Backup and tried to reprogram the RTC but its still giving out a constant square wave and non-changing variables on debug. Would it be the case that I need a new DS1307 module?
 
Last edited:

hippy

Senior Member
When I first started this project, I mistakingly had my PSU leads the wrong way round and thus fed the power into my circuit 'backwards'. This only occured for about 10 seconds before I realised my mistake however it worked fine after that. Could this have anything to do with it not working now? ... Would it be the case that I need a new DS1307 module?
Incorrect voltages can damage an IC and it is impossible to tell how any damage may materialise. It would be worth trying another DS1307; if that works then it would be a reasonable guess the other was damaged, if it behaves the same then the issue is likely something else.

Was the PICAXE connected when you had reverse voltage applied ? It could be worth trying a replacement for that too.

The 209 value you are seeing just happens to be $D1 or %11010001 which is a variant on the DS1307 device address so the issue may be with I2C comms, something wrong in that respect, rather than anything wrong with the chips.
 

LED Maestro

Senior Member
Thanks hippy. The picaxe was connected at the same time but I have tried another program, a simple led cycling program, just to check that the chip still works, which it does. Probably not the greatest test I am sure :) Having said this, I will get another chip and RTC Module and try them. If it is something wrong with the comms, could you suggest any solutions?
Westaust, I tried setting current time but that still gives my the same results.
 

hippy

Senior Member
If it is something wrong with the comms, could you suggest any solutions?
Visibly check for broken wires, dislodged or disconnected pull-ups, dry joints or anything else amiss, and also test with a resistance meter. It could be that the chips have come loose in their sockets or failing to make good contact.

It may be clutching at straws but removing IC's and re-inserting them can sometimes fix things.
 

John West

Senior Member
Running an LED toggling test to see if a PICAXE is working properly is not the same thing as checking to see if the chip works properly. It is a little "brain" of a chip with a lot of different processes that your LED toggling left untested that the clock circuit may use.

I never again truly trust any IC that I have powered up with power pins reversed, and am quick to swap it out at the first sign of problems, (and I always mount my PICAXE chips in machine pinned sockets for that very reason.)

BTW, a Schottky diode properly placed in a power lead during construction ensures that that I don't do any damage latter on if I hook things up backwards. It does have a voltage drop, but it's small and often well worth (in circuit protection) the voltage drop it causes.
 

LED Maestro

Senior Member
Thanks Hippy! I checked all the contacts before asking on here and they seemed to be OK (tested the wires with my multimeter just to be sure). I have also moved all of the components to the other side of my breadboard just to be sure but to no avail!
John, I didn't think my little 'test' would work either. Strangely enough though, I have already put a diode into my circuit yesterday to protect it from further reverse PSU voltage but thanks for the suggestion. I will get myself another 28X2 and RTC module and hope this solves the problem which I am confident it will.
Thanks for all your help
 

Hemi345

Senior Member
What about the crystal? You might order another one of those as well just to be sure.

<--- do I need to do anything to my post count, like change from a byte variable to a word, so it doesn't overflow on my next post? ;) :D
 
Last edited:

LED Maestro

Senior Member
Huh...I didn't think about the crystal. I was so focused on the IC's! Thanks for that. I will order one of those as well. Again, thanks for the suggestion.

With regards to your post count...LOL! I think it would be best to come up with some sort of mathematical code to prevent overflow, or if you prefer the simple way, I would go with word!! Brilliant bit of goofiness there!!:D
 

Paix

Senior Member
Hmmmmm, mention of breadboards and crystals, I bought a DS1307 and crystal from Rev Ed some while ago and saw them just the other day. What struck me was how tiny the crystal was and how fine the wires are . . . problematical in a breadboard possibly?

I think that when you find the problem, if you do, then it will turn out to be something that will make you blush. Good luck though and I hope you solve the mystery soon.
 

westaust55

Moderator
Going back to post 1,
"I get a constant square wave on the output"
Does that mean the RTC output sqw pin is alternating high and low or is it always high or low?

A value of 255 when read on the i2c comms data line suggests that the RTC is not responding at all so the pull up resistors hold the data line high and all bits in the read data are 1 resulting in %11111111 = 255.
RTC
 

John West

Senior Member
On the topic of Xtal problems, I have lost Xtals simply by pre-cutting their leads to length, instead of cutting off the excess lead after I'd soldered them in. Now I treat them all like small FET's, conductive foam, anti-stat mat, etc.
 

hippy

Senior Member
A value of 255 when read on the i2c comms data line suggests that the RTC is not responding at all so the pull up resistors hold the data line high and all bits in the read data are 1 resulting in %11111111 = 255.
Value 209 is however also being returned which is a variant on the DS1307 device address so this may be indicating an issue with I2C comms ( post #5 ) and incorrectly wired or intermittent bus connection.

I would doubt a faulty crystal would affect I2C operations or values read but it might be possible.
 

Paix

Senior Member
Point well taken Hippy, there would be no square wave if the crystal was totally defunct.

Good point also from John regarding the shock when clipping component leads. Easy not to consider, but bits fly because of clipping shock, also potentially transferred to the stationary component.
 

Julianosborn

New Member
hi all new to the forum.

i have a 28X2 connected to a DS1307 Real time clock. tried it on the main board, intermittent count. built a new board using only a 28X2 and a DS1307 on board and have the same reading on the second board, seconds count ( Explained later). all spare inputs pins are connected to ground on the 28X2 via a 4k7 resistor on the 28x2. I have connected a 1k res to the pulse SQR Output , to a BCX38C Darlington Transistor - LED to indicate the RTC O/P is working. this works fine. Have used some code from the PICAXE Forum group. but get the result of :-

0123456789
101112131415????
16171819202122232425
262728293031????
32333435363738394041
424344454647????
48495051525354555657
585960616263????
64646667686970717273
747576777879????
80818283848586878889
0123456789
101112131415????
16171819202122232425
262728293031????
32333435363738394041
424344454647????
48495051525354555657
585960616263????
64646667686970717273
747576777879????
80818283848586878889

sorry if the file is big , but need help! ( monitored this for over an hour and the same readings,
 

Julianosborn

New Member
Its such a privilege to be in the Group, have written lots of NEXTION programs and am getting very familiar with SIM800L Module.
 

hippy

Senior Member
This is what I see in the Debug window, seconds after i initiate the code after a download.
View attachment 23187
That seems to be correct for a few seconds after the 11:59:00 on 2003-12-03 you are setting your RTC to.

The problem you are having is that the RTC data comes back as BCD but you are looking at the decimal value.

For example mins=89 decimal. That's %01011001 in binary $59 in hex / BCD.

If you add this after your READI2C it will convert all the BCD numbers read to decimal and then they will appear correct in the DEBUG screen -
Code:
year    = year    / 16 * $FA + year
month   = month   / 16 * $FA + month
date    = date    / 16 * $FA + date
hours   = hours   / 16 * $FA + hours
mins    = mins    / 16 * $FA + mins
seconds = seconds / 16 * $FA + seconds
As a future tip; it's usually best to post your code as copy-and-paste text wrapped in [code]...[/code] tags rather than as screenshots.
 

Julianosborn

New Member
Thank you very much Hippy! You are a star!

that worked a treat. every thing now in line and displaying the correct time on the nextion display.
 
Top