changed from bs2e to bs2p, now I2C doesn't work!
electricbrewer
Posts: 2
Hi, new guy here....
I'm having trouble with my I2C and DS1621 interface...
I was able to implement the nuts and volts DS1621 code for I2C on my basic stamp 2e, with 3 temp sensors running perfectly. I started to run out of program space so I figure that purchasing the 2p-24 stamp would eliminate all the extra code needed for the DS1621. I adjusted the code into this:
SDA PIN 8 ' SDA on 0; SCL on 1
'
[noparse][[/noparse] Constants ]
DevType CON %1001 << 4 ' Device type
DevAddr CON %111 << 1 ' address = %000 -> %111
Wr1621 CON DevType | DevAddr ' write to DS1621
Rd1621 CON Wr1621 | 1 ' read from DS1621
RdTemp CON $AA ' read temperature
RdCntr CON $A8 ' read counter
RdSlope CON $A9 ' read slope
StartC CON $EE ' start conversion
StopC CON $22 ' stop conversion
AccTH CON $A1 ' access high temp limit
AccTL CON $A2 ' access low temp limit
AccCfg CON $AC ' access config register
TempHi CON 25 ' 26C = ~77F
TempLo CON 22 ' 21C = ~72F
DegSym CON 176 ' degrees symbol
'
[noparse][[/noparse] Variables ]
tempIn VAR Word ' raw temp from DS1621
sign VAR tempIn.BIT8 ' - sign (after alignment)
halfC VAR tempIn.BIT0 ' half-degree C bit
tempC VAR Word ' temp in Celsius
tempF VAR Word ' temp in Fahrenheit
'
[noparse][[/noparse] Initialization ]
Setup:
I2COUT SDA, Wr1621, [noparse][[/noparse]AccCfg, %1010] ' set TOut = active high
PAUSE 1000 ' allow EE write
I2COUT SDA, Wr1621, [noparse][[/noparse]StartC] ' start continuous
PAUSE 1000
Set_Thermostat:
I2COUT SDA, Wr1621, [noparse][[/noparse]AccTH, TempHi] ' set high threshold
PAUSE 1000
I2COUT SDA, Wr1621, [noparse][[/noparse]AccTL, TempLo] ' set low threshold
PAUSE 1000
Demo_Screen:
DEBUG CLS,
"DS1621 Demo", CR,
"
", CR,
DegSym, "C... ", CR,
DegSym, "F... "
'
[noparse][[/noparse] Program Code ]
Main:
DO
PAUSE 1000 ' delay between reads
GOSUB Get_Temp ' get current temperature
DEBUG CRSRXY, 6, 2, SDEC tempC, CLREOL, ' display
CRSRXY, 6, 3, SDEC tempF, CLREOL
LOOP
END
'
[noparse][[/noparse] Subroutines ]
Get_Temp:
I2COUT SDA, Wr1621, [noparse][[/noparse]RdTemp]
PAUSE 50
I2CIN SDA, Rd1621, [noparse][[/noparse]tempIn.HIGHBYTE, tempIn.LOWBYTE]
PAUSE 50
tempIn = tempIn >> 7 ' correct bit alignment
' Celsius
tempC = (tempIn / 2) | ($FF00 * sign)
' Fahrenheit
tempF = (tempIn | ($FF00 * sign)) + 110
tempF = tempF * 9 / 10 - 67 ' convert to F
RETURN
==============================================================
Now all I get is the Debug window showing up the two same numbers -1, and 30 after Celsius a Fahrenheit. Even when I unplug the temperature sensors completely and let the code run, it just does the same thing, whereas before if I didn't address the correct sensor right it wouldn't work.
Anyone have a clue why this would occur???
I really appreciate your help in saving a senior design student!!
Justin
I'm having trouble with my I2C and DS1621 interface...
I was able to implement the nuts and volts DS1621 code for I2C on my basic stamp 2e, with 3 temp sensors running perfectly. I started to run out of program space so I figure that purchasing the 2p-24 stamp would eliminate all the extra code needed for the DS1621. I adjusted the code into this:
SDA PIN 8 ' SDA on 0; SCL on 1
'
[noparse][[/noparse] Constants ]
DevType CON %1001 << 4 ' Device type
DevAddr CON %111 << 1 ' address = %000 -> %111
Wr1621 CON DevType | DevAddr ' write to DS1621
Rd1621 CON Wr1621 | 1 ' read from DS1621
RdTemp CON $AA ' read temperature
RdCntr CON $A8 ' read counter
RdSlope CON $A9 ' read slope
StartC CON $EE ' start conversion
StopC CON $22 ' stop conversion
AccTH CON $A1 ' access high temp limit
AccTL CON $A2 ' access low temp limit
AccCfg CON $AC ' access config register
TempHi CON 25 ' 26C = ~77F
TempLo CON 22 ' 21C = ~72F
DegSym CON 176 ' degrees symbol
'
[noparse][[/noparse] Variables ]
tempIn VAR Word ' raw temp from DS1621
sign VAR tempIn.BIT8 ' - sign (after alignment)
halfC VAR tempIn.BIT0 ' half-degree C bit
tempC VAR Word ' temp in Celsius
tempF VAR Word ' temp in Fahrenheit
'
[noparse][[/noparse] Initialization ]
Setup:
I2COUT SDA, Wr1621, [noparse][[/noparse]AccCfg, %1010] ' set TOut = active high
PAUSE 1000 ' allow EE write
I2COUT SDA, Wr1621, [noparse][[/noparse]StartC] ' start continuous
PAUSE 1000
Set_Thermostat:
I2COUT SDA, Wr1621, [noparse][[/noparse]AccTH, TempHi] ' set high threshold
PAUSE 1000
I2COUT SDA, Wr1621, [noparse][[/noparse]AccTL, TempLo] ' set low threshold
PAUSE 1000
Demo_Screen:
DEBUG CLS,
"DS1621 Demo", CR,
"
", CR,
DegSym, "C... ", CR,
DegSym, "F... "
'
[noparse][[/noparse] Program Code ]
Main:
DO
PAUSE 1000 ' delay between reads
GOSUB Get_Temp ' get current temperature
DEBUG CRSRXY, 6, 2, SDEC tempC, CLREOL, ' display
CRSRXY, 6, 3, SDEC tempF, CLREOL
LOOP
END
'
[noparse][[/noparse] Subroutines ]
Get_Temp:
I2COUT SDA, Wr1621, [noparse][[/noparse]RdTemp]
PAUSE 50
I2CIN SDA, Rd1621, [noparse][[/noparse]tempIn.HIGHBYTE, tempIn.LOWBYTE]
PAUSE 50
tempIn = tempIn >> 7 ' correct bit alignment
' Celsius
tempC = (tempIn / 2) | ($FF00 * sign)
' Fahrenheit
tempF = (tempIn | ($FF00 * sign)) + 110
tempF = tempF * 9 / 10 - 67 ' convert to F
RETURN
==============================================================
Now all I get is the Debug window showing up the two same numbers -1, and 30 after Celsius a Fahrenheit. Even when I unplug the temperature sensors completely and let the code run, it just does the same thing, whereas before if I didn't address the correct sensor right it wouldn't work.
Anyone have a clue why this would occur???
I really appreciate your help in saving a senior design student!!
Justin
Comments
Justin
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
· -- Carl, nn5i