PDA

View Full Version : 2 wire sensor problem



precision
- 2nd April 2007, 13:58
I attempt to read ds1621 with pic16f877A, but always reading 00 value;
Where is mistake ? Please .....

' pic16f877a

DEFINE OSC 4
INCLUDE "MYLCD.BAS" ' lcd on portb
CMCON = 7
ADCON1 = 7

SCL VAR PORTD.2
SDA VAR PORTD.3

;( A0,A1,A2 = gnd )

W0 var word
ds var byte
Startconvert var byte

Startconvert = $EE ' Initiates temperature conversion.
ds = %10100000 ' device address


start:
i2cwrite SDA,SCL,ds,$AC,[0] ' Access Config
pause 100
i2cwrite SDA,SCL,ds,Startconvert ' Start Conversion
pause 750
gosub gettemp
lcdout $fe,1
lcdout "Temperature = ",dec2 W0

pause 800
goto start



gettemp:
i2cread SDA,SCL,ds,$AA,[W0] ' Read last converted temperature value from temperature register.
W0 = W0 >> 8
return

skimask
- 2nd April 2007, 14:18
I attempt to read ds1621 with pic16f877A, but always reading 00 value;
Where is mistake ? Please .....



Pullups on SCL/SDA lines?

precision
- 2nd April 2007, 14:47
Yes
4.7k 1/4 watt resistors pullups from both, scl and sda pin.


.

skimask
- 2nd April 2007, 20:42
Try getting rid of the W0 >> 8 and see what happens in the LCDout statement. And get rid of the DEC2 in the LCDout... just to see if you get any numbers that make any sense at all.

Darrel Taylor
- 2nd April 2007, 22:07
The device address for a DS1621 is %1001xxx0, not %1010xxx0.
<br>