Ds1307 rtc

DBoyd

New Member
Hello,

When using the following code, the display (a parallax serial lcd) will display the correct time for the first five seconds.
The subsequent loops display irrelevant data. It might be cycling through dow/day/month/year once, but it does not display a recognizable pattern after the first cycle.
Will someone point out what I'm missing?

Thanks.
DBoyd

Code:
symbol secs     = b0
symbol mins     = b1
symbol hour     = b2
'symbol dow      = b3  
'symbol day      = b4  
'symbol month    = b5  
'symbol year     = b6  
'symbol century  = b7
'symbol control  = b8  

  hi2csetup i2cmaster, %11010000, i2cslow, i2cbyte
  pause 50

main:
hic2in (secs,mins,hour)                  ; Receive information from clock 
bcdtoascii secs, b15, b16               'seconds
bcdtoascii mins, b11, b12               'minutes
bcdtoascii hour, b13, b14                'hours  

serout c.1, t2400, (128, "Time ", b13, b14, ":", b11, b12, ":", b15, b16) 
pause 5000
goto main 

end
 

Attachments

Last edited by a moderator:

neiltechspec

Senior Member
Try this.

Code:
symbol secs = b0
symbol mins = b1
symbol hour = b2
symbol dow = b3
symbol day = b4
symbol month = b5
symbol year = b6

hi2csetup i2cmaster, %11010000, i2cslow, i2cbyte
pause 50

main:
hic2in $0 (secs,mins,hour,dow,day,month,year) ; Receive information from clock
bcdtoascii secs, b15, b16 'seconds
bcdtoascii mins, b11, b12 'minutes
bcdtoascii hour, b13, b14 'hours

serout c.1, t2400, (128, "Time ", b13, b14, ":", b11, b12, ":", b15, b16)
pause 5000
goto main

end

Neil.
 

DBoyd

New Member
Thanks for the reply.
Changed $0 to B0.
But still had intermittent problem.

Cleared bytes B0,B1 and B2 after every loop and it works great.
Can you anyone tell me why clearing the bytes fixed this problem?

Thanks to Neil.

DB


Code:
symbol secs = b0
symbol mins = b1
symbol hour = b2
symbol dow = b3
symbol day = b4
symbol month = b5
symbol year = b6

hi2csetup i2cmaster, %11010000, i2cslow, i2cbyte
pause 50

main:
hi2cin b0, (secs,mins,hour,dow,day,month,year) ; Receive information from clock
bcdtoascii secs, b15, b16 'seconds
bcdtoascii mins, b11, b12 'minutes
bcdtoascii hour, b13, b14 'hours

serout c.1, t2400, (128, "Time ", b13, b14, ":", b11, b12, ":", b15, b16)
pause 1000
b0 = 0
b1 = 0 
b2 = 0
goto main

end
 
Last edited by a moderator:

westaust55

Moderator
Welcome to the PICAXE forum.

Before executing the BCDTOASCII commands you need to mask of some bits in the hours variable. How many bits depends whether you are operating in 12 or 24 hour mode.

Hours = hours AND Mask

For 24 hour mode Mask= %00111111
For 12 hour mode Mask = %00011111


Next:
1. What voltage are you operating the DS1307 at?
2. Do you have a standby/backup battery connected? What voltage?
3. What program have you used to set up the DS1307 RTC?
4. Do you have pull up resistors on the i2c comms bus lines?

A schematic and maybe photo of the hardware could be useful.

Okay re reading your second post.
You are using b0 as the register pointer in the Hi2cIN command.
Thus if B0 is not cleared to zero you are pointing at the wrong registered in the DS1307 to read data. By default b0 is zero when program first starts so would do 1 pass oaky.


Change the line to
Hi2cIN 0, .....
Should fix that problem.

If there are then still intermittent problems then more info as per questions may help.
 
Last edited:

DBoyd

New Member
Why were you using 'hi2cin b0' and not 'hi2cin 0' ??
Umm? Because I thought that is what you were trying to do and because it worked.
Isn't it the same thing minus the port designation?
I was using a 18m2+ which has more than one port so I thought that might be part of the problem.

Thanks again.
DB
 

westaust55

Moderator
Umm?
Because I thought that is what you were trying to do and because it worked.
It only worked after you also added commands to clear byte variable b0.
Did the information provided at post 4 make sense?

Isn't it the same thing minus the port designation?
With i2c you do not need Port or Port.Pin designations.
The two pins used for i2c under the PICAXE/PIC hardware are fixed/pre-defined.

I was using a 18m2+ which has more than one port so I thought that might be part of the problem.
No, not the case. as mentioned above, the i2c pins are fixed/pre-defined and within PICAXE nomenclature no port designation is required for i2c comms.
 
Last edited:

DBoyd

New Member
It only worked after you also added commands to clear byte variable b0.
Did the information provided at post 4 make sense?
I understand the concept.

With i2c you do not need Port or Port.Pin designations.
The two pins used for i2c under the PICAXE/PIC hardware are fixed/pre-defined.
No, not the case. as mentioned above, the i2c pins are fixed/pre-defined and within PICAXE nomenclature no port designation is required for i2c comms.
This makes sense.
 
Top