Shop OBEX P1 Docs P2 Docs Learn Events
can someone please tell me what is wrong with this — Parallax Forums

can someone please tell me what is wrong with this

NewBeeNewBee Posts: 35
edited 2010-06-14 12:16 in BASIC Stamp
I simply want to write data into the DS1307 SRAM, then read it, and get back wht I believe I put in it.

' =========================================================================
'
'·· File.......
'·· Purpose....
'·· Author.....
'·· E-mail.....
'·· Started....
'·· Updated....
'
'·· {$STAMP BS2p}
'·· {$PBASIC 2.5}
'
' =========================================================================

'
[noparse][[/noparse] Program Description ]
'
' This program demonstrates the access and control of an external real-
' time-clock chip, the DS1307.

'
[noparse][[/noparse] I/O Definitions ]
SDA············ PIN···· 0······················ ' I2C serial data line
SCL············ PIN···· 1······················ ' I2C serial clock line
'
[noparse][[/noparse] Constants ]
DS1307········· CON···· %1101 << 4
yr············· CON···· 20
'
[noparse][[/noparse] Variables ]
DecConvert····· VAR···· Byte
'
[noparse][[/noparse] EEPROM Data ]

'
[noparse][[/noparse] Initialization ]
Reset:
· #IF ($STAMP < BS2P) #THEN
··· #ERROR "Please use BS2 version: SW21-EX33-DS1307.BS2"
· #ENDIF
Setup:
· DEBUG CLS,
······· "DS1307 Demo", CR,
······· "
", CR
· I2COUT SDA, DS1307, 55, [noparse][[/noparse]DEC yr]·········· ' update clock registers
· I2CIN SDA, DS1307, 55, [noparse][[/noparse]DEC decconvert]··········· ' retrieve clock registers
· DEBUG DEC ? decconvert, "out", CR

Comments

  • Redd DawgRedd Dawg Posts: 26
    edited 2010-06-12 23:42
    I can't be of help other than to say you might change your thread name to something more descriptive and then the pros will hook you up. Something more like..."write data into the DS1307 SRAM"

    Mark

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • $WMc%$WMc% Posts: 1,884
    edited 2010-06-13 06:23
    NewBee

    Your Stamp does what the code you write tells it to do

    You don't have a DO-LOOP or a Main:-GOTO. You need some kind of a routine.

    Once the code gets to DEBUG DEC ? deconvert, "out", CR

    Theirs nothing left for the Stamp to do. The Stamp does the next instruction after the DEBUG DEC ?. This is nothing. So the Stamp does nothing.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    The Truth is out there············___$WMc%___···························· BoogerWoods, FL. USA


    want speed?·want·to use the Propeller?·want to stay with BASIC___www.propbasic.com___


    You can feel stupid by asking a stupid question or You can be really·stupid by not asking at all.

    ·
  • NewBeeNewBee Posts: 35
    edited 2010-06-13 13:19
    Indeed, the code does exactly what I intended it to do, demonstate z single write to SRAM an then a read from it. I stripped everything else out because if someone wanted to run it they wouldn't be trouble shooting my code just validating my problem. As stated in my original post:

    I simply want to write data into the DS1307 SRAM, then read it, and get back wht I believe I put in it.

    Thank you very much for your help.
  • Ron CzapalaRon Czapala Posts: 2,418
    edited 2010-06-13 20:14
    Take the DEC modifier out of the I2CIN and IC2OUT statements

    This works fine for me:

    '·· {$STAMP BS2p}
    '·· {$PBASIC 2.5}
    '
    ' =========================================================================

    '
    [noparse][[/noparse] Program Description ]
    '
    ' This program demonstrates the access and control of an external real-
    ' time-clock chip, the DS1307.

    '
    [noparse][[/noparse] I/O Definitions ]
    SDA············ PIN···· 0······················ ' I2C serial data line
    SCL············ PIN···· 1······················ ' I2C serial clock line
    '
    [noparse][[/noparse] Constants ]
    DS1307········· CON···· %1101 << 4

    yr············· CON···· 25
    '
    [noparse][[/noparse] Variables ]

    by1 VAR Byte
    by2 VAR Byte

    DecConvert····· VAR···· Byte
    '
    [noparse][[/noparse] EEPROM Data ]

    '
    [noparse][[/noparse] Initialization ]
    Reset:
    · #IF ($STAMP < BS2P) #THEN
    ··· #ERROR "Please use BS2 version: SW21-EX33-DS1307.BS2"
    · #ENDIF
    Setup:
    · DEBUG CLS,
    ······· "DS1307 Demo", CR,
    ······· "
    ", CR

    · I2COUT SDA, DS1307, 55, [noparse][[/noparse]yr]·········· ' update clock registers
    · I2CIN SDA, DS1307, 55, [noparse][[/noparse]decconvert]··········· ' retrieve clock registers
    · DEBUG DEC ? decconvert, "out", CR
    PAUSE 2000

    FOR by1 = 0 TO 5
    · DEBUG DEC2 by1, " in", CR
    · I2COUT SDA, DS1307, 55, [noparse][[/noparse]by1]·········· ' update clock registers··· \
    · PAUSE 500
    · I2CIN SDA, DS1307, 55, [noparse][[/noparse]by2]··········· ' retrieve clock registers
    · DEBUG DEC2 ? by2, "out", CR
    NEXT
    · END
  • NewBeeNewBee Posts: 35
    edited 2010-06-14 04:15
    Ron,

    Thanks for your help. I notice some minor differences in my code and your code. I ran your code and it works then I ran mine and it works too.

    So I'm really confused. But sincerely, thank you very much.
  • Ron CzapalaRon Czapala Posts: 2,418
    edited 2010-06-14 12:16
    NewBee,
    · When your program executes this:· I2COUT SDA, DS1307, 55, [noparse][[/noparse]DEC yr] it is writing two bytes - '2' and '5'· (ascii 50 and acsii 53)

    · When your program executes this:· I2COUT SDA, DS1307, 55, [noparse][[/noparse]yr] it is writing one byte -·ascii 25

    · You need to study the DEC modifier and how it works when reading and writing data.
    The formatters receive bytes of data, wating for the first byte that falls within the range of characters they accept (e.g., “0” or “1” for binary, “0” to “9” for decimal, “0” to “9” and “A” to “F” for hex, and “-” for signed variations of any type). Once they receive a numeric character, they keep accepting input until a nonnumeric character arrives or (in the case of the fixed length formatters) the maximum specified number of digits arrives.
    '   {$STAMP BS2p}
    '   {$PBASIC 2.5}
    ' -----[noparse][[/noparse] I/O Definitions ]-------------------------------------------------
    SDA             PIN     0                       ' I2C serial data line
    SCL             PIN     1                       ' I2C serial clock line
    ' -----[noparse][[/noparse] Constants ]-------------------------------------------------------
    DS1307          CON     %1101 << 4
    yr              CON     25
    ' -----[noparse][[/noparse] Variables ]-------------------------------------------------------
    by1 VAR Byte
    by2 VAR Byte
    DecConvert      VAR     Byte
    ' -----[noparse][[/noparse] EEPROM Data ]-----------------------------------------------------
    ' -----[noparse][[/noparse] Initialization ]--------------------------------------------------
      I2COUT SDA, DS1307, 55, [noparse][[/noparse]DEC yr]
      GOSUB ShowBytes
      I2COUT SDA, DS1307, 55, [noparse][[/noparse]yr]
      GOSUB ShowBytes
    END
    ShowBytes:
      FOR by1 = 55 TO 57
        I2CIN SDA, DS1307, by1, [noparse][[/noparse]by2]
        DEBUG DEC by1, " [noparse][[/noparse]", DEC by2, "] "
        IF by2 > 0 THEN
          DEBUG "'", by2, "' "
        ENDIF
        DEBUG CR,CR
      NEXT
    RETURN
      END
    
    
Sign In or Register to comment.