Shop OBEX P1 Docs P2 Docs Learn Events
DS1307 Clock — Parallax Forums

DS1307 Clock

Duane C. JohnsonDuane C. Johnson Posts: 955
edited 2012-06-28 08:28 in Propeller 1
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:
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

  • KyeKye Posts: 2,200
    edited 2012-02-23 19:46
    My code doesn't let you access the first 8 registers out of the 64. For the read/write SRAM functions. Take a look at the source in the code. It limits the address you pass and then adds 8 to it.

    Thanks,
  • Duane C. JohnsonDuane C. Johnson Posts: 955
    edited 2012-02-23 20:03
    Hi Kye;

    My bad!

    I forgot that I had messed around with this a few months ago.
    PUB readSRAM(index) '' 12 Stack Longs
    
    '' ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    '' // Returns the selected SRAM value at the specified index on sucess and false on failure.
    '' //
    '' // Index - The byte location in SRAM to check. (0 - 55).
    '' // Index - The byte location in SRAM to check. (0 - 63).  zzzz
    '' ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
    '  return getRam(((index <# 55) #> 0) + 8)
      return getRam(((index <# 63) #> 0) + 0)  ' zzzz
    
    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
  • KyeKye Posts: 2,200
    edited 2012-02-23 20:10
    It can, it just doesn't make much sense to do so since the read time function does that.
  • Duane C. JohnsonDuane C. Johnson Posts: 955
    edited 2012-02-23 20:22
    Kye wrote: »
    It can, it just doesn't make much sense to do so since the read time function does that.
    Well, I was interested in making a copy of the 64 registers in RAM. Then I could experiment with it.
    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
  • Mark_TMark_T Posts: 1,981
    edited 2012-02-24 02:19
    Well, I was interested in making a copy of the 64 registers in RAM. Then I could experiment with it.
    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.
  • KyeKye Posts: 2,200
    edited 2012-02-24 06:22
    Yup,

    The $FF you are getting is saying that the DS1307 ACK'ed and was alive.
  • avionikerenavionikeren Posts: 64
    edited 2012-06-27 13:48
    Hi,

    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?
  • KyeKye Posts: 2,200
    edited 2012-06-27 17:22
    I'm not sure what's going on with the serial port. But it looks fine. Did you add pull up resistors to the system? The I2C lines need to be pulled to high. See the schematic in the source code.

    The readTime function return -1 on success and 0 on failure BTW.

    ---

    Yes, you do not need a battery. Just supply power and ground.
  • avionikerenavionikeren Posts: 64
    edited 2012-06-27 23:08
    Ah, I can see now that only the SDA line are pulled high.
    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...
  • avionikerenavionikeren Posts: 64
    edited 2012-06-28 08:24
    Works perfect now, thanks for the tip!
  • KyeKye Posts: 2,200
    edited 2012-06-28 08:28
    What you are looking at is the I2C bus. Both the SDA and SLC lines must be pulled high per I2C bus spec.

    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,
Sign In or Register to comment.