RTC clock problem

monteghirfo

New Member
Hi,

I've a problem whit 1307 RTC and my picaxe chip.

I can read seconds, minutes and hours fron the clock and all work fine. But after some hours the communication stops.
Seeing the code explorer variable, I see that all variables go to 255!!!

How is it possible?

Adding to this, all variable, before the bug are updated every 1 second as written in the program, but w0 always go up. may be this the problem? a sort of overflow?

Thank you,
Stefano.
 

monteghirfo

New Member
symbol seconds = b0
symbol mins = b1
symbol hour = b2
symbol day = b3
symbol date = b4
symbol month = b5
symbol year = b6
symbol control = b7

; set PICAXE as master and DS1307 slave address
hi2csetup i2cmaster, %11010000, i2cslow, i2cbyte
main:
; Read the clock time
; readi2c 0,(b1,b2)
hi2cin 0,(b0,b1,b2)

readadc C.4,b8 ; read ADC1 into variable b8
if hour=$00 and mins=$00 and b8<=120 then attiva1
if hour=$16 and mins=$00 and b8<=120 then attiva1
if hour=$17 and mins=$00 and b8<=120 then attiva1
if hour=$18 and mins=$30 and b8<=120 then attiva1
pause 2000 'legge l'ora ogni 10s
debug
goto main

etc.....

----- This is the code that read seconda, minutes and hours...

and this is screenshot. why w0 is so high??

Thanks!picaxeRTC.jpg
 

inglewoodpete

Senior Member
I can read seconds, minutes and hours fron the clock and all work fine. But after some hours the communication stops.
Seeing the code explorer variable, I see that all variables go to 255!!!
The code explorer values only relate to the simulator. From what you say, it is not clear to me whether you are using a real PICAXE chip or the simulator. (User posted while I was typing my post :))

If you are using a real PICAXE chip and not the simulator and the returned values change to 255, it suggests that there is a problem with the i2c bus wiring. The bus should not be more than 1 metre long. Also, check the soldering of any joints since bad connections can cause i2c bus lock-ups.

and this is screenshot. why w0 is so high??
w0 (16-bits) is a combination of b0 and b1 (8-bit variables). These values should not be viewed as a word because you are using byte variables in this part of your program.
 
Last edited:

hippy

Technical Support
Staff member
and this is screenshot. why w0 is so high??
w0 (16-bits) is a combination of b0 and b1 (8-bit variables). These values should not be viewed as a word because you are using byte variables in this part of your program.
In addition, you are viewing the b0 and b1 variables as decimal, however the values returned from the DS1307 are in Binary-Coded Decimal (BCD). From your screen shot -

Seconds = 21 => $15
Minutes = 64 => $40
Hour = 21 => $15

So the time the DS1307 thought it was when you took that screen shot seems to have been 15:40:15.
 

westaust55

Moderator
If you are intending to display the time by sending serially with say the SEROUT command then you can us the
BCdTOASCII command to extract the tens and units from each part (hours, mins and seconds)
http://www.picaxe.com/BASIC-Commands/Variables/bcdtoascii/

If you are going to us the time internally you can either:
(A) use the BCDTOASCII command but then need to subtract $30 for decimal instead of ASCII
(B) do some simple math to convert the BCD encoded values read for on the DS1307 into a decimal number that we humans understand.

So you can see and understand the process:
Units = BCB //10
Tens = BCD / 16
Decimal = tens * 10 + units

This can be reduced into less lines but shows you the fundamentals.
 

monteghirfo

New Member
I forget to set a pause every i2c reading. It may be these the problem that crashed data transfer?
The row with "pause 2000" was commented.

Now I set a pause and all work fine!
 

hippy

Technical Support
Staff member
It seems unlikely that having the PAUSE commented out would cause the problem so it may be that the problem has resolved itself and that is just coincidence.

Reading 255 could indicate that the I2C connections were not reliable and you may also get 255 if the DS1307 enters its battery backup mode which can depend upon the supply voltage. Perhaps the voltage is different today or batteries have slightly recovered some voltage if batteries are being used. Declining voltage could explain why it worked for some hours then stopped working.
 

westaust55

Moderator
Further to hippys information/comments:
1. What is the supply source plug pack or batteries?
2. What is the supply voltage (4.5Vdc, 5Vdc, or other?)
3. Do you have a 3V Lithium back-up battery connected to the DS1307?
4. If no DS1307 back-up battery is the battery pin tied to Ground / 0 volt?
 

monteghirfo

New Member
1. the source is a 12V supply source plus 5 Volts stybylized with LM7805.
2. supply voltage to the picaxe 5V.
3. I'v a lithium battery for back-up.

Thanks.
 
Top