ds1307 clock and i2c commun. prob

fred_b

Member
I am trying out the ds1307 real time clock chip but after several hours I am having no luck. Could someone look over the attachments and tell me if you can spot the problem? I would greatly appreciate it.

Note: The program is downloading successfully to the 18X picaxe chip (LED flashes during operation).

Debugging- all vars read 0

main:
'First program the date

' initialize
i2cslave %11010000, i2cslow, i2cbyte
' sec min hr day date mon yr control
writei2c 0, ($00,$59,$11,$03,$25,$12,$03,$10)
pause 50


doit:
i2cslave %11010000, i2cslow, i2cbyte
readi2c 0, (b0,b1,b2)

high 5
wait 1 ' flash led
low 5

debug
goto doit
 

Attachments

BCJKiwi

Senior Member
Have a look here;
http://www.picaxeforum.co.uk/showthread.php?t=8078

Different registers hold different items for read.
0 holds the seconds only so only one byte variable will get data.

Also, try replacing the debug with a sertxd as per the code shown in the above post. Debug interacts with some commands /timing - never use it myself anymore.

Also the i2cslave line should not be repeated in the body of the program - just once in the initialisation section.

There is a heartbeat output on the chip to which an LED (with resistor) can be connected to verify the Clock is powered and 'clocking along'.
 
Last edited:

fred_b

Member
still no comm

I tried those things. No luck.
The heartbeat LED would not flash. I even tried writing a number to RAM register 8. But could get no reading on that either. Maybe the clock chip is bad?

i2cslave %11010000, i2cslow, i2cbyte
' sec min hr day date mon yr control
writei2c 0, ($00,$09,$13,$06,$26,$10,$07,%00010000,$11)
pause 50


doit:

readi2c 8, (b0)

bcdtoascii b0,b1,b2 ' DS1307 stores data in BCD format
sertxd ("reading",b1,b2) ' Write output to terminal
wait 1

goto doit
 

pbutton

New Member
You appear to have the second 4.7k pullup resistor connected to Out5 instead of Out1 on the 18X. Thus the i2c line SDA has no pullup.
 

eclectic

Moderator
@fred_b

BCJ and pebutton have indicated your problems.
This is just adding a little.

Make sure that the wires on your crystal actually make connection.
(I soldered two thicker legs to my crystal.)

Use the PE datalogger wizard to set the time on your DS1307.
Clear the memory on the 18X.

Then, try this simple program.

Code:
'ds1307 clock read 
'Forum Fri 130209
;http://www.picaxeforum.co.uk/showthread.php?t=11627
'Leg 5 = SDA = C4 (28X1)  OUT1 (18X)
'Leg 6 = SCL = C3 (28X1)  OUT4 (18X)

#picaxe 18X

i2cslave %11010000, i2cslow , i2cbyte

main:
readi2c 0,(b9,b10,b11)

bcdtoascii b11, b12,b13 : sertxd (b12,b13)
bcdtoascii b10, b12,b13 : sertxd (" ",b12,b13)
bcdtoascii b9,  b12,b13 : sertxd (" ",b12,b13,cr,lf)

pause 960 ;Adjust as required

goto main
In my circuit, I've wired the “heartbeat” LED from
V+ > LED > 330 Ώ > leg 7

Yellow wire SCL to 18X output 4
Blue wire SDA to 18X output 1

e
 

Attachments

fred_b

Member
Thanks for all of your help. Must be getting close!

I moved the 4.7k resistor. (I was sure I had checked those a hundred times!)

Put in the v+>LED>330ohm>leg2. (Now it stays on continuously)

The output on the terminal looks like: reading??reading??reading??....

Almost time to leave for work so I don't have time to adjust the program right now but the commands seem to be correct:

i2cslave %11010000, i2cslow, i2cbyte
writei2c 0, ($00,$09,$13,$06,$26,$10,$07,%00010000)
pause 50

doit:

readi2c 0, (b0)
bcdtoascii b0,b1,b2
sertxd ("reading",b1,b2)
wait 1
goto doit
 

Attachments

Last edited:

eclectic

Moderator
@fred

Please look at the attachment.

The first reading ?? values were with
2 x AA cells. (3V)

Then, I repowered with 3 x AA ~ 4.5V

e
 

Attachments

westaust55

Moderator
what voltage are you using?

The DS1307 is rated to operate between 4.5V and 5.5V.

So it would be out of spec to operate with just 2 x AA 1.5V battereis.
 

fred_b

Member
problem solved

I did have 3 pretty new AA batteries but the voltage was just low enough that it wouldn't work.

I put in new batteries and voila! fixed it.

Thanks for your help!
 
Top