DS1307 interface with 28X2

LED Maestro

Senior Member
Hi,
I have a DS1307 module hocked up to a picaxe 28x2 with SDA connected to pin 15 and SCL connected to pin 14 both with appropriate pull up resistors and an led connected to the SQW output which is flashing at a very steady rate I am glad to say. I have a small amount of code to set the time, date etc and then read it back in debug (see below). The problem is that in debug, all variables are stuck at 255, no movement, nothing! My wiring is certainly correct and both the chip and RTC module are new.
Any advice would be greatly appreciated

Code:
#Picaxe28x2

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
; 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 = $59 ; 59 Note all BCD format
let hour = $11 ; 11 Note all BCD format
let day = $03 ; 03 Note all BCD format
let date = $25 ; 25 Note all BCD format
let month = $12 ; 12 Note all BCD format
let year = $03 ; 03 Note all BCD format
let control = %00010000 ; Enable output at 1Hz
hi2cout 0,(seconds,mins,hour,day,date,month,year,control)

main:
hi2cin 0,(b0,b1,b2,b3,b4,b5,b6,b7)
debug b1
pause 2000
goto main
 

westaust55

Moderator
From the datasheet:
If a backup supply is not required, VBAT must be grounded. The nominal power-fail trip point (VPF) voltage at which access to the RTC and user RAM is denied is set by the internal circuitry as 1.25 x VBAT nominal.
What is the supply voltage used for the PICAXE and the DS1307?

Again from the datasheet for the DS1307:
Supply Voltage VCC min = 4.5 V typical = 5.0 V max = 5.5 V
If you are using 3 x AA cells try three new fresh cells in case the supply voltage VCC is slightly low.
 

LED Maestro

Senior Member
I am feeling like a right twit now! my apologies to you both. it appears i had a faulty connection on the SDA line. i have just swapped the jumper, reprogrammed (just to be sure) and am currently debugging and it is working brilliantly.
Apologies once again
Have a nice day
 

nick12ab

Senior Member
I have a 1.5V button cell battery backup on VBAT and my supply voltage is 4.5V from a regulated PSU
According to the datasheet, the battery voltage should be at least 2.0V if a battery is used.

The lower battery voltage shouldn't stop it from working, but try removing the battery and connecting Vbat straight to 0V to rule this out.

Also, when you say that 'all variables are stuck at 255', do you mean all variables or just the ones used in the program? It is odd that you can write to it but not read from it since the flashing SQW LED shows this.

Do you have a resistor with that SQW LED?

EDIT:
I am feeling like a right twit now! my apologies to you both. it appears i had a faulty connection on the SDA line. i have just swapped the jumper, reprogrammed (just to be sure) and am currently debugging and it is working brilliantly.
Apologies once again
Have a nice day
Perhaps it just so happened that the wire was making the connection when you first sent data to the DS1307 then it stopped working when you tried to read the data.
 

LED Maestro

Senior Member
thanks Nick. Funnily enough i did remove the battery and just connect straight to ground but this didn't appear to make any difference and, again, my apologies for not being clear, only the programmed variables were stuck at 255. And I concur with your hypothesis about the wire but either way I am happy to have it working now.
Oh and yes I do have a resistor with the SQW LED! Aditionally my RTC module is connected straight to my 4.5V PSU, forgot to mention that!
I have been debugging for the past half an hour now and it is still keeping time so I believe all is sorted.
Whilst I am here though, if you don't mind my asking, if I am correct in saying that all data is in BCD then how may one convert that to be displayed on an LED module?
Many thanks
 
Last edited:

nick12ab

Senior Member
Whilst I am here though, if you don't mind my asking, if I am correct in saying that all data is in BCD then how may one convert that to be displayed on an LED module?
Yes the time and date is in BCD.

What LED module? Stating that can help get a more specific answer.

But some things to try:
  1. bcdtoascii
  2. Use two let commands with bit masks and bit shifts to split the BCD variable into two variables which can be combined into a single decimal variable:
    Code:
    	dig1 = bcdvar >> 4		'Use /16 on parts that don't support >>
    	dig2 = bcdvar & %00001111
    	decvar = dig1 * 10 + dig2
  3. Use the bcdtobin operator (in a let command) to convert the value from BCD to decimal - X1/X2 only
 

LED Maestro

Senior Member
Sorry, I want to display the time on a custom LED module i created. Blocks of 10 x 10 multiplexed LED's, to save on the o/p's, that i have connected together to form an LED display. Much like an LCD display but with LED's.
thanks for the suggestion. I will give those a go.
Many thanks for your help
 

Armp

Senior Member
[*]Use two let commands with bit masks and bit shifts to split the BCD variable into two variables which can be combined into a single decimal variable:
Or to conserve space and reuse the variable:
Code:
Secs= Secs /16 *250 +secs   ' Convert BCD to Binary by subtracting 6*high nibble
 

westaust55

Moderator
For the X1 and X2 parts there is the BCDTOBIN which will convert the BCD encoded value to a binary value.

so you can use:
decvar = BCDTOBIN bcdvar
 
Top