Picaxe 40x1 > ds1307, All values hashed

Hi guys i have a picaxe 40x1, and just bought a ds1307 chip from dontronics today, i put it in my breadboard, inserted the crystal between pins 1 and 2, put in a cr2032 battery on pin 3, gnd on pin 4, vcc on pin 5, and led with a resistor to vcc on pin6, slc on pic 7, sda on pin 8.

i tried the ds1307 sample program (adding the /16's) and was getting values like 152/152/178 etc

then tried the following simple program :

main:
i2cslave %11010000, i2cslow, i2cbyte
readi2c 0, (b0,b1,b2)
sertxd(#b2,":",#b1,":",#b0,13,10)
pause 1000
goto main

but all i get is :

255:255:255


i am using the 28x/40x proto board. with all the jumpers in the default positions.

Thanks
Lachlan
 
edit :

It appears now its running through the program ( i put a sertxd("main loop") inside main: and i get lots of main loops, but nothing from the i2c not even 255's
 
Last edited:
ok, now that the data lines are tied high with a 5k1 resistor, it seems to be working flawlessly, although after i set the time with the datalogger>ds1307 time set wizard, its displaying 17:03 when its 5:44 ?
 
this is the code i am using to display the time


the code at the bottom is used to set the time at 6:00 pm or 18:00 the clock is displaying 17:19

i must have hashed something, also i dont quite get if im using the numbers correctly when setting the time, it seems to be that i enter the decimal number with a $ infront of it and it becomes bcd ? well thats what the ds1307 example illustrates.


Code:
symbol seconds = b0
symbol mins = b1
symbol hour = b2
symbol day = b3
symbol date = b4
symbol month = b5
symbol year = b6
symbol control = b7
symbol temp = b8

' set DS1307 slave address
	i2cslave %11010000, i2cslow, i2cbyte


' uncomment this line to update the clock time
' goto start_clock 


' read time and date and display on serial LCD module

main:
	readi2c 0,(seconds,mins,hour,day,date,month,year)
	
'	debug 
		
sertxd(13,10)

	let temp = date & %0011000 / 16
	sertxd(#temp)
	let temp = date & %00001111
	sertxd(#temp,"/")

	let temp = month & %0001000 / 16
	sertxd(#temp)
	let temp = month & %00001111
	sertxd(#temp,"/")

	let temp = year & %11110000 / 16
	sertxd(#temp)
	let temp = year & %00001111
	sertxd(#temp," ")

	let temp = hour & %00110000 / 16
	sertxd(#temp)
	let temp = hour & %00001111
	sertxd(#temp,":")

	let temp = mins & %0111000 / 16
	sertxd(#temp)
	let temp = mins & %00001111
	sertxd(#temp,":")

	let temp = seconds & %01110000 / 16
	sertxd(#temp)
	let temp = seconds & %00001111
	sertxd(#temp)

	pause 5000
	goto main



'write time and date e.g. to 11:59:00 on Thurs 25/12/03
start_clock:
	let seconds = $00	' 00 Note all BCD format
	let mins    = $52	' 59 Note all BCD format
	let hour    = $17	' 11 Note all BCD format
	let day     = $03	' 03 Note all BCD format
	let date    = $18	' 25 Note all BCD format
	let month   = $01	' 12 Note all BCD format
	let year    = $10	' 03 Note all BCD format
 	let control = %00010000 ' Enable output at 1Hz

	writei2c 0,(seconds,mins,hour,day,date,month,year,control)

	end
 
and then while im looking at the input buffer and tv simultaneously


18/01/10 17:19:04
18/01/10 17:19:08
18/01/10 17:19:13
18/01/10 17:19:18
18/01/10 17:19:23
18/01/10 17:19:28
18/01/10 17:19:33
18/01/10 17:19:38
18/01/10 17:19:43
18/01/10 17:19:48
18/01/10 17:19:52
18/01/10 17:19:57
18/01/10 18:00:02
18/01/10 18:00:07
18/01/10 18:00:12
18/01/10 18:00:17
18/01/10 18:00:22
18/01/10 18:00:27
18/01/10 18:00:32
18/01/10 18:00:36

it just jumped 40 minutes and appears to be working ?
 

Pfrogs

Member
You managed to jump forward in time..that should be something! :D

Sorry, I've never worked with ds1307 before, but certainly soon someone will help you explain this phenomenon. Just couldn't help it commenting your Back to the future clock ;)
 

hippy

Ex-Staff (retired)
It hasn't jumped 40 minutes. If the time were not "17:19:57" but "17:59:57" then the following "18:00:02" would be right, and looking at the tens decoding for minutes ...

let temp = mins & %0111000 / 16

You've got a missing zero, it should be -

let temp = mins & %01110000 / 16

You have similar bugs elsewhere.

You enable the LED to flash at 1Hz in your program :)

Previously removed ( sorry - had misread where the OP indicates LED is working ) : I believe the SQW LED has to be enabled and SQW can only sink current so the LED+R has to connect between +V and pin.
 
Last edited:

MartinM57

Moderator
also should the led connect to the sqw pin, flash once a second? it currently is, i assumed that it was meant to be 1khz though.
Yes, but as Hippy says, from +V via a resistor to the SQW pin.

Have a look at the data sheet for the CONTROL register settings. %00010000 enables SQW output at 1Hz - so all is well. Unfortunately, you can't get 1Khz out of SQW...
 
thanks guys.

i didnt write that code at all, it is purely the ds1307 sample code, but i added the /16

shouldnt that get updated with the changes?
 

MartinM57

Moderator
it is purely the ds1307 sample code
From where?

EDIT: I see no official (aka Rev-Ed) code samples that are incorrect - but a lot of incorrect code being posted around the Internet. Remember, 'not all you read on the Internet is correct'...
 
Last edited:
rather than echo'ing the value out of the serial port, the high nibble first then the second.

let temp = hour & %00110000
serout 7,N2400,(#temp)
let temp = hour & %00001111
serout 7,N2400,(#temp,":")

how can i convert the bcd value hour, to decimal and store it in hour again?
 

MartinM57

Moderator
I see no official (aka Rev-Ed) code samples that are incorrect
...that's because I've never looked in that folder (didn't know it was there!).

There does appear to be an error with a missing 0 in some of the masks - but I'm confused whether your /16 is in your code now or not ... it shouldn't be there if you have the masks correct? EDIT - of course it should be there. Engage brain before typing MartinM57 ;)
 
Last edited:

hippy

Ex-Staff (retired)
i didnt write that code at all, it is purely the ds1307 sample code, but i added the /16
The sample code was incorrect, and both the "/16" and incorrect bit masks have been corrected but there hasn't been a subsequent BAS805 Programming Editor release since which explains its lack of propagation. The sample code will be fixed in the next release.
 
fantastic, thanks for all your help hippy.

it looks as if everything is working perfectly for now, i will have to figure out how to convert the bcd to decimal without just sending the first nibble out and then the second, maybe i store the first in temp 1 the second in temp 2 and "&" them together ?
 

hippy

Ex-Staff (retired)
Or -

ReadI2c ..., ( ... hour ... )
temp = hour & %00110000 / 16 * 10
temp = hour & %00001111 + temp
SerTxd( # temp )

"temp = BcdToBin hour" will achieve the same.
 
thanks heaps. I am currently using the bcdtobin functions, but i wanted to use some other chips that dont support that function.

Thanks again.
Lachlan
 
Top