can someone please tell me what is wrong with this
NewBee
Posts: 35
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
' =========================================================================
'
'·· 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
Mark
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
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.
·
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.
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
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.
· 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.