Shop OBEX P1 Docs P2 Docs Learn Events
Ds1307 — Parallax Forums

Ds1307

NewzedNewzed Posts: 2,503
edited 2004-09-14 03:20 in BASIC Stamp
Does anyone know if there is a N&V column on operating the DS1307 with a BS2, or any other source.· I have a program which I thought was OK but can't get it to work so I just wanted to check it against a working program.

Thanks

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Visit the Piggyback Page

http://hometown.aol.com/newzed/index.html
·

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-09-07 18:43
    The NX-1000-24/40 docs have a bit of code for the DS1307 ... but you could always download the spec sheet and roll your own for more fun.

    BTW, I'm writing about I2C in my November column, and the DS1307 will be included.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • NewzedNewzed Posts: 2,503
    edited 2004-09-07 21:17
    Breadboarded up a DS1307 DIP and the program works perfectly.· Checked the crystal part number on the Piggyback and I think I have a crystal with 6pf load cap instead of 12.5pf.· I'm sure that is the problem.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Sid Weaver
    Visit the Piggyback Page

    http://hometown.aol.com/newzed/index.html
    ·
  • NewzedNewzed Posts: 2,503
    edited 2004-09-08 14:29
    After I got the program working OK, I was thinking about the DS1302, which uses a HEX2 format for setting and reading the clock.· I wondered if that would work on the DS1307, so I reset the clock parameters for HEX2 format, eliminated the BCD conversion routines and ran the program.· Works perfectly!· It appears to run a bit faster, the code is neat and tidy, and best of all I reduced the program length by over 200 bytes.

    I'll let it run for a bit, and then if everything seems OK, I'll post the HEX2 format code here.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Sid Weaver
    Visit the Piggyback Page

    http://hometown.aol.com/newzed/index.html
    ·
  • NewzedNewzed Posts: 2,503
    edited 2004-09-09 14:15
    My HEX2 format version of the DS1307 for BS2/BS2E/BS2SX has been has been running for about 30 hours and is performing flawlessly, so I am attaching the code in case anyone has an application for it.

    Please be aware that this is a modification of the original BS2 I2C code for the 1307.· You should have no problems with it, but if something should arise, please contact me since this is my responsibility.

    I think you will find that this code runs a bit faster than the BCD version, and it will save you over 200 bytes of program space.· It uses Stamp I/O ports 8 and 9, but these maybe changed to 0 and 1 if you prefer.· Standard I2C protocol requires the use of 0/1 or 8/9 so it is suggested you use these ports just to conform.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Sid Weaver
    Visit the Piggyback Page

    http://hometown.aol.com/newzed/index.html
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-09-09 14:38
    When you bit-bang I2C with SHIFTOUT and SHIFTIN you can use any pins -- you're not limited to 0/1 and 8/9 (that only applies to I2COUT and I2CIN on the BS2p and BS2pe).

    Your Get_Clock and Set_Clock routines could be shortened by using a loop and indexing from the minutes register.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office


    Post Edited (Jon Williams) : 9/9/2004 3:17:34 PM GMT
  • NewzedNewzed Posts: 2,503
    edited 2004-09-09 15:59
    Like this:

    Put_Clock:

    ·GOSUB I2C_Start
    · i2cWork = Wr1307
    · GOSUB I2C_TX_Byte
    · i2cWork = 0
    · GOSUB I2C_TX_Byte
    · FOR idx = 0 TO 5
    · LOOKUP idx, [noparse][[/noparse]seconds, minutes, hours, day, date, month, year], i2cwork
    · GOSUB I2C_TX_Byte
    · NEXT
    · GOSUB I2C_Stop
    · RETURN

    I tried doing the Get_Clock but since that is backwards to Put_Clock I couldn't figure out how to do it.· I wrote:

    Get_Clock:
    · GOSUB I2C_Start
    · i2cWork = Wr1307
    · GOSUB I2C_TX_Byte
    · i2cWork = 0
    · GOSUB I2C_TX_Byte
    · GOSUB I2C_Start
    · i2cWork = Rd1307
    · GOSUB I2C_TX_Byte
    · FOR idx = 0 TO 5
    · GOSUB I2C_RX_Byte
    · LOOKDOWN i2cwork, [noparse][[/noparse]seconds, minutes, hours, day, date, month]
    · NEXT
    · GOSUB I2C_RX_Byte_Nak························ ' final byte - send NAK
    · year = i2cWork······························· 'year
    · GOSUB I2C_Stop
    · RETURN

    but I really don't think that will work.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Sid Weaver
    Visit the Piggyback Page

    http://hometown.aol.com/newzed/index.html
    ·
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-09-09 17:20
    You're right, that way won't work -- assign your clock variables in the same order they appear in the DS1307 you can treat them as an array and loop through it. I know for a fact that this works because I wrote DS1307 code yesterday with my updated I2C routines for the BS2, and I have block write and block read subroutines that do exactly as I just described. The code will be published in the November issue of Nuts & Volts.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • NewzedNewzed Posts: 2,503
    edited 2004-09-09 18:54
    I give up.· I'll just wait until November.

    Sid
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-09-09 20:17
    Giving up so easily? As it turns out, I posted an earlier version of my DS1307 program in this thread:

    http://forums.parallax.com/forums/default.aspx?f=5&m=2373&g=2443#m2443

    My N&V code has new (clearer) variable names and will allow the user to use buttons to reset the clock, or to change the time.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • NewzedNewzed Posts: 2,503
    edited 2004-09-09 20:35
    Jon, that link talks about I2C devices, MCP 23016 and so on.

    Sid
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-09-09 20:53
    And if you take a little bit of time to search that thread, you'll see that I uploaded a DS1307 program for the BS2. The DS1307 is, afterall, and I2C device.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • NewzedNewzed Posts: 2,503
    edited 2004-09-12 22:03
    Finally got the crystal replaced in my DS1307 and its working great.· Downloaded Jon's program and modified it to fit my particular needs and it is also working great.· Learned a lot from·his program - I didn't know you could shiftout all the clock parameters by indexing on seconds, so that really shortens the program.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Sid Weaver
    Visit the Piggyback Page

    http://hometown.aol.com/newzed/index.html
    ·
  • GaryMGaryM Posts: 7
    edited 2004-09-14 00:11
    I can't get this part to do anything with the BS2 and your software......

    Let me clarify·.. Your software is trying to work.· The Time Set/Read menu comes up.

    The data returned on a read is only 0's.

    I gave up guessing if I had the magic crystal... wanting to·eliminate another variable... But with an externally 32.7 Khz clock on Pin 1, its still not working.

    Anyone know how to get these to show some sign of life?· I bought 4 new parts·which were well protected from static...

    Thanks

    Post Edited (GaryM) : 9/14/2004 12:33:34 AM GMT
  • Mag748Mag748 Posts: 263
    edited 2004-09-14 01:25
    Just a quick Q about the N&V, how soon after the magazine comes out will that column be availible on the parallax website?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • GaryMGaryM Posts: 7
    edited 2004-09-14 03:20
    Whoa.
    The chip lives !

    Embarassing electrical fault. Fixed *S*

    Two questions now:

    Why on earth is this thing counting in Hex?· Changing it to output "DEC2" doen'st make it produce resonable numbers, either.· I tried Sid's code first then Jon's.· Both have hex outputs???

    And how does one set the square wave output?·
Sign In or Register to comment.