PDA

View Full Version : can't read from DS1621



HOBBPROG
- 12th May 2008, 22:53
Hello, maybe some one can help me out. I just created a very simple program. this program should set a temperature in the DS1621 and then read and display the messured temperature on a 16x2 lcd. DS1621 can be programed using I2C. Writing to the ds621 is no problem but reading from it is.

Am I overlooking a typo?
I can't find what is wrong, just getting the message: 'reading temp. error'
'
' LCD should be connected as follows:
' LCD PIC
' DB4 PortA.0
' DB5 PortA.1
' DB6 PortA.2
' DB7 PortA.3
' RS PortA.4 (add 4.7K pullup resistor to 5 volts)
' E PortB.3
' RW Ground
' Vdd 5 volts
' Vss Ground
' Vo 20K potentiometer (or ground)
' DB0-3 No connect
'
' DS1621 connected as follows
' DS1621 PIC
' SDA (1) PortB.0 (pullup 10k to 5 volts)
' SCL (2) PortB.1 (pullup 10k to 5 volts)
' A0,A1,A2 to GND
' TOUT led with R to 5 volts



DEFINE I2C_HOLD 1

SDA var PORTB.0 ' I2C data pin
SCL var PORTB.1 ' I2C clock pin
T0 var byte ' temperatuur msb
T1 var byte ' temperatuur lsb
T2 var byte
T3 var byte
Tin var word
T2in var byte[2]
Status_reg var byte ' status register
Status_val var byte ' waarde in status register
j var byte

Pause 1500 ' Wait for LCD to startup

start:
lcdout $fe,1
lcdout $fe,$80+5,"Hello" ' go to first line
lcdout $fe,$c0+5,"World"
Pause 1500 ' Wait 1.5 secondS


T0 = 22 'high temp.
T1 = 0
T2 = 20 'low temp.
T3 = 0

Status_reg=$AC
Status_val=$2

'set status register and start conversion
j=1
I2CWrite SDA,SCL,$90,[$EE],bogus
pause 100
j=2
I2CWrite SDA,SCL,$90,Status_reg,[status_val],bogus
pause 1000
'setting the temperature
j=3
I2CWrite SDA,SCL,$90,$A1,T0,[T1],bogus
j=4
I2CWrite SDA,SCL,$90,$A2,T2,[T3],bogus


'read temperature
pause 250
j=5
i2cread sda,scl,$90,$AA,[Tin],bogus
Tin = Tin>>8
lcdout $fe,1,"temp. is: ",Tin


bogus:
if j = 1 then lcdout $fe,1,"startconv. error"
if j = 2 then lcdout $fe,1,"statusreg. error"
if j = 3 then
lcdout $fe,1,"setting high"
lcdout $fe,$c0,"temp. error"
endif
if j = 4 then
lcdout $fe,1,"setting low"
lcdout $fe,$c0,"temp. error"
endif
if j = 5 then
lcdout $fe,1,"reading temp."
lcdout $fe,$c0,"error"
endif

pause 3000 'even pauze en dan opnieuw proberen
goto start