DS1307 Clock
Duane C. Johnson
Posts: 955
Hi All;
I have Kye's DS1307 clock driver working nicely.
However, I don't understand how to read address 0, the seconds register?
Don't get me wrong, Kye's code reads seconds correctly.
But the SRAM reader doesn't work. It's probably me though.
Here's my code snippets:
See, I can read all 64 addresses except the first.
The SRAM matches the time read using Kye's time reader.
I can't see any restrictions in the spec.
I even tried a second read.
What am I doing wrong?.
Duane J
I have Kye's DS1307 clock driver working nicely.
However, I don't understand how to read address 0, the seconds register?
Don't get me wrong, Kye's code reads seconds correctly.
But the SRAM reader doesn't work. It's probably me though.
Here's my code snippets:
ser.str(string(def#Cr,def#Lf)) ' Get Clock SRAM and put in timeRam ser.str(string(" ")) repeat i from 0 to 7 ser.hex(i,2) ser.str(string(space)) ser.str(string(def#Cr,def#Lf)) timeRam[0] := rtc.readSRAM(0) ' Throw away read repeat i from 0 to 56 step 8 ser.hex(i,2) ser.str(string("-")) repeat j from 0 to 7 timeRam[i+j] := rtc.readSRAM(i+j) ser.hex(timeRam[i+j],2) ser.str(string(space)) ser.str(string(def#Cr,def#Lf))
2130/02/23 d5 18:55:45 00 01 02 03 04 05 06 07 00-FF 55 18 05 23 02 D0 00 08-08 09 0A 0B 0C 0D 0E 0F 10-10 11 12 13 14 15 16 17 18-18 19 1A 1B 1C 1D 1E 1F 20-20 21 22 23 24 25 26 27 28-28 29 2A 2B 2C 2D 2E 2F 30-30 31 32 33 34 35 36 37 38-38 39 3A 3B 3C 3D 3E 3F
See, I can read all 64 addresses except the first.
The SRAM matches the time read using Kye's time reader.
I can't see any restrictions in the spec.
I even tried a second read.
What am I doing wrong?.
Duane J
Comments
Thanks,
My bad!
I forgot that I had messed around with this a few months ago. It seemed like the thing to do as an experiment.
However, this begs the question.
Why can't the seconds register be read?
Your routine does it?
Just wondering.
Duane J
I didn't say it was a good reason.%*)
I really did do a bunch of experiments but register 0 always reads $FF.
Why?
Duane J
Because the code in getRam special-cases when index==0 in order to read the time registers. Not too hard to spot if you read the code.
The $FF you are getting is saying that the DS1307 ACK'ed and was alive.
I have trouble reading the DS1307 and I am not very experienced with SPIN.
Can you please take a look at my code to see if I am doing something wrong there?
The RTCEngineStart returns -1, but all other commands returns 0
I am running without battery, but it should work when I connect it to ground?
The readTime function return -1 on success and 0 on failure BTW.
---
Yes, you do not need a battery. Just supply power and ground.
I use the same pins as the EEPROM for the propeller, so I thought it was okay as it is in the schematics for propeller and eeprom where only a 4.7k resistor for the SDA line is added.
Is there any good explanation for why only the SDA is pulled high in the recommended schematic for eeprom?
And why do they use 4.7k when other recommends 10k. What should I use?
Will try to add a 10k to the SCL later today...
You can get away with not having the SCL line pulled high... sometimes... other times it can be a catastrophe if the chip is driving current into the SCL line.
Google I2C bus and read about it for more information.
The resistors are called pull-ups. Their value is not that important. They just make sure that the line is weakly pulled up to a default voltage state. Lower values of pull up resistors switch faster but have a higher current consumption. High values do just the opposite.
Thanks,