DS1307 Doesnt display data

George Sephton

Senior Member
I have connected the DS1307 to my PICAXE 28X1 as on the i2c manual but when it starts the only thing that shows are Square Blocks and colons [][]:[][]:[][]

Here's my code
Code:
....
i2cslave %11010000,i2cslow,i2cbyte

PowerOnReset:

writei2c 0,($00,$37,$22)
GOSUB InitialiseLcd
Goto Main
END
Main:
debug
readi2c 0,(b0,b1,b2)

outbyte = $80
gosub SendCmdByte

For counter = 0 to 1
lookup counter, (b2), outbyte
gosub SendDataByte
next counter
outbyte = ":"
gosub SendDataByte
For counter = 0 to 1
lookup counter, (b1), outbyte
gosub SendDataByte
next counter
outbyte = ":"
gosub SendDataByte
For counter = 0 to 1
lookup counter, (b0), outbyte
gosub SendDataByte
next counter

goto Main
....
ignoring the symbols.

The only difference between the i2c manual's circuit and mine is the resistance used, ive used 1.2K instead of 4.7K and a 330R instead of 470R. Could that be the problem?

EDIT: Just used 4 1.2K resistors in series, still no luck.
 
Last edited:

westaust55

Moderator
George,

1. You DO need to tell us what the DS1307 is mounted on.
It could be AXE033, AXE110, breadboard or home made board.

If the AXE033 then with the display as mentioned, it seems like you may have the "CLK" jumper in place.
This gives a display like 00:00:00 00/00/00 if the DS1307 chip is not present/working. See AXE033 manual page 5.

Your code sugegsts however that it is your LCD interfaced with the 74HC164 chip in which case item 2 below is more relevant.

2. You need to sent the full data to the DS1307 chip, not just the time part. First three lines become:
Code:
i2cslave %11010000,i2cslow,i2cbyte
PowerOnReset:
writei2c 0,($00,$55,$11,[B][COLOR="Red"]$03,$26,$12,$08,$10[/COLOR][/B])
The $10 is a control byte that starts the clock amongst other things.


Finally, can I respectfully suggest that you have a read at post 4 in this thread:
http://www.picaxeforum.co.uk/showthread.php?t=10982

It may help you understand how to clearly state what hardware you have, what you have done, and what the symptoms are.
I get the impression that yo need to also have a good read of some of the Rev Ed manuals on i2c and the DS1307. Even the AXE033 manual with respect to the DS1307 in i2c mode though that is very similar to the general i2c tutorial.
 
Last edited:

George Sephton

Senior Member
Its a solderless breadboard, everything im doing is one a few solderless breadboard connected.

Ive done your additions and still no luck, the blocks mean there's no data in b0/b1... dont they? The DS1307 is powered, I know, the LED connected to pin 7 is lit, the crystal is there SCL and SDA and both connected to the correct pins (the bottom 2) with a 1K resistor coming off it to ground.
 

westaust55

Moderator
i2c pull-up resistors

For the i2c pull up resistor, 4.7kOhm is the max value for 100kHz.

I have seen recommendations to drop these to 1.8 kOhm for 400kHz to improve the speed to high-low and low to high transitions for data.

However I am still using 4.7kOhm without problems at 400kHz.
 
Last edited:

westaust55

Moderator
Its a solderless breadboard, everything im doing is one a few solderless breadboard connected.

Ive done your additions and still no luck, the blocks mean there's no data in b0/b1... dont they? The DS1307 is powered, I know, the LED connected to pin 7 is lit, the crystal is there SCL and SDA and both connected to the correct pins (the bottom 2) with a 1K resistor coming off it to ground.
No need for a 1kOhm resistor from any pin to ground.

Try changing the last value in the writei2c statement to $00 (instead of $10)
That will change the pulse rate to the LED on pin 7 to 1 Hz so you can see it flash. If no flashing then clock is not running.
 

George Sephton

Senior Member
No flashing but I looked on debug and b0,b1 and b2 all have the values 255 ($FF) but before this thread they only had the values 0. Ive tried swapping the 2 wires at the bottom of the PICAXE around in case I got the wrong pins but still nothing. Is this line the only thing needed to start the DS307? How else would the clock start?
Code:
i2cslave %11010000,i2cslow,i2cbyte
 

papaof2

Senior Member
Mayhap you are in too much of a hurry?

Post #2 has the code needed to start the clock - with part of it in red.

John
 

George Sephton

Senior Member
Ok, Ive been looking around the forum and found a few threads and have copied one of them. Its the most simple and basic way of doing this and ive added a debug. But again all the vars are 255:

Code:
'************************************************* *****
i2cslave %11010000, i2cslow, i2cbyte 'set slave parameter


'************************************************* *****
'arbitrarily setting the clock to begin with:
' 37:14:03 03:08:10
' ss:mi:hh yy:dd:mm

'************************************************* *****
'b0, b1, b2, b3, b4, b5, b6, b7
writei2c 0, ($37, $14, $03, $04, $03, $08, $03, $10)

pause 500

'**************** read back the results ***************
main:
readi2c 0,(b0,b1,b2,b3,b4,b5,b6,b7)

debug 
goto main
 

westaust55

Moderator
A value of 255 is indicating that you do not have i2c comms. The pull up resistor is holding data line high so it reads "1" for each bit hence the 255 = %11111111
 

George Sephton

Senior Member
Success! I can now work from that code but im not sure why it took so long. Thanks so much westaust for all your time and effort youve been so helpful, im actually really grateful, but really sorry it took so long.
Cheers.
 

lbenson

Senior Member
Just to be clear about your resistors, they should be "pull-ups"--SCL and SDA connected with 4K7 resistors, give or take, to +5V (or +4.5V, etc.).
 

westaust55

Moderator
DS1307 Real Time Clock

George,

Great to see that you have got it going.


For your information. here is a piece of code that will write to and read to the RTC AND some of its spare RAM.

Give it a try if you wish.


Code:
Init:

	i2cslave %11010000, i2cslow, i2cbyte
	
;now set the clock 	
	writei2c 0, ($00, $53, $12, $03, $26, $12, $08, $10)
	pause 50
; also write to some of the RTC extra RAM (there are 56 bytes)
	writei2c 8, ($12, $22, $32, $42, $52, $62, $72)
; then wait 10 seconds - YES 10 seconds 

; now check RTC has been set 
       readi2c 0, (b0, b1, b2, b3, b4, b5, b6)
       pause 50
       
; and look if data was written/read from RAM ok as well
       readi2c 8, (b7, b8, b9, b10, b11, b12)

	debug
	pause 5000
see if the values you see in the variables window matches the data written.

RTC should advance but even if the clock is not working, the second line of data should be written into the first 8 bytes (out of 56 bytes) of user RAM in the RTC chip.

Will at least give an idea (in future) whether you are actually writing to the DS1307
 

George Sephton

Senior Member
It looks good, My PC has just died and cant find the serial to usb converter so I cant test it. Also I reset the circuit (by pulling the positive in and out of the breadboard) and im back where I started, but I know how to fix it this time, if that basic code made it work then I need to look at my code to make sure it doesnt and start resetting the PICAXE with the reset button. Thanks for all your help, Ill have to carry on tomorrow.

Thanks,
George S.
 

westaust55

Moderator
No flashing but I looked on debug and b0,b1 and b2 all have the values 255 ($FF) but before this thread they only had the values 0. Ive tried swapping the 2 wires at the bottom of the PICAXE around in case I got the wrong pins but still nothing. Is this line the only thing needed to start the DS307? How else would the clock start?
Code:
i2cslave %11010000,i2cslow,i2cbyte
For your information, the line you referenced is only setting up the PICAXE to communicate with the RTC (DS1307).

The line starting writei2c 0, . . . . writes the time and date to the RTC and starts it working.
 

George Sephton

Senior Member
Ok its fixed, for those doing a similar thing you have to make sure the i2c connections are the right way round and that the DS1307 requires the 3V input on pin 3 or it doesn't work thats been the problem really.

By the way the Debug wait for ages it doesnt actually connect in your script. And finally is there any reason why it won't show on an LCD screen? Im outputting b0 and it doesnt display. However I have been having a few problems with the LCD screen on the 28X1 so we'll see what comes up.
 

George Sephton

Senior Member
I know what its display: Its display the last column on the right of the debug table, starting as symbols and ending at AA-ZZ but I dont want to display that I want to display the 2nd column along with the value $24 but without the $, is that possible?
 

George Sephton

Senior Member
Found it, BCDTOASCII.
Its done, I have a clock that outputs to an LCD Screen! Thanks everyone, if anyone needs to code, just shout and ill post it.
 
Top