Hi (again),
I've build a simple circuit that use a 18X and a DS1624 i2c temperature sensor.
I've used two 4,7K pullup resistor on i2c bus, but I'm still having problem maybe with bin->dec conversion or i2c data transfer (sometimes i read 255°C).
I'm powering the picaxe via a LM7805 with a small cap between power rails.
Could someone help me to check the code please?!
Tnx
I've build a simple circuit that use a 18X and a DS1624 i2c temperature sensor.
I've used two 4,7K pullup resistor on i2c bus, but I'm still having problem maybe with bin->dec conversion or i2c data transfer (sometimes i read 255°C).
I'm powering the picaxe via a LM7805 with a small cap between power rails.
Could someone help me to check the code please?!
Tnx
Code:
'Device Address
SYMBOL ads1624 = %10010000
'Device Specifics
SYMBOL access_config = $ac
SYMBOL rd_temp = $aa
SYMBOL start_convert_t = $ee
main:
GOSUB init_ads1624 'set single shot mode
GOSUB rtd ' read tempeture and display
END
init_ads1624:
I2CSLAVE ads1624, I2CFAST, I2CBYTE
WRITEI2C access_config, ($00) 'protocol error?
PAUSE 300
WRITEI2C start_convert_t, ($00)
PAUSE 100
RETURN
rtd:
READI2C rd_temp, (b0, b1)
PAUSE 200
w0=%0001100100010000
'bin->dec
w1 = b1 'decimal part
'fractional conversion
w2 = w0 & %0000000000001000 MAX 1 * 03125 'minimum temp increment 0.03125°
w2 = w0 & %0000000000010000 MAX 1 * 06250 + w2
w2 = w0 & %0000000000100000 MAX 1 * 12500 + w2
w2 = w0 & %0000000001000000 MAX 1 * 25000 + w2
w2 = w0 & %0000000010000000 MAX 1 * 50000 + w2
SERTXD("Temp = ",#w1,".") 'Show decimal part
IF b1 > 16 THEN NoLeadZero 'Add or not a zero after the dot
SERTXD("0")
NoLeadZero:
SERTXD(#w2,CR,LF) 'fract part
PAUSE 200
GOTO rtd