PDA

View Full Version : DS1920 IButton



scottl
- 1st November 2007, 19:10
I am trying to communicate with an IButton DS1920. I am using the ONEWIRE.pbp example. According to the datasheet it communicates the same as the DS18S20 or DS18B20. I am able to communicate with the IButton but the temperatures are all over the place. From 32, 84, 112, 225, etc... I am using a 4.7K ohm pull up resistor to 5V. Also tested at 3.6V same results.

Is there anything special with the DS1920? Has anyone used this and willing to share their success or failures?

Note: I am only wanting to communicate with just one at a time! No onewire networks!

Thanks in advance,

Scott

scottl
- 2nd November 2007, 00:39
I have found this sample on the forum and would like to see if someone can try this and tell me if this works? I would like to use this on a PIC12F675 or PIC16F628!



@ DEVICE pic12F675, INTRC_OSC_NOCLKOUT
@ DEVICE pic12F675, WDT_OFF
@ DEVICE pic12F675, PWRT_OFF
@ DEVICE pic12F675, MCLR_OFF
@ DEVICE pic12F675, BOD_OFF
@ DEVICE pic12F675, CPD_OFF
@ DEVICE pic12F675, PROTECT_OFF

dEFINE OSC 4
DEFINE OSCCAL_1K 1 ' osc calibration

Ansel = 0 ' Analog off
CMCON = 7 ' Comparators off
ADCON0 = 7 ' Configure A/D channel
WPU = %000000 'dISABLE wEAK pULLUPS
TRISIO = %10010 ' Set all I/O's to outputs

temperature var word 'DS1820 read Temperature
TempNeg var byte 'temperature sign -/+
Sign VAR BIT
TempC VAR WORD

'*****DS1820 VARS AND SETTINGS*******
count_remain var byte 'DS1820 coumter of remain bits
count_per_c var byte 'DS1820 counter per C bits
'**********************************

DQ Var GPIO.2 ' One-wire data pin
PAUSE 1000

Main:
GOTO Read_Temp


'******DS1820 READING******
Read_Temp:
OWOut DQ, 1, [$CC, $44] ' Start temperature conversion
waitloop:
OWIn DQ, 4, [count_remain] ' Check for still busy converting
If count_remain = 0 Then waitloop
OWOut DQ, 1, [$CC, $BE] ' Read the temperature
OWIn DQ, 0, [temperature.LowByte, temperature.HighByte, Skip 4, count_remain, count_per_c]
' SEROUT2 GPIO.0,16468, ["+Raw", IBIN16 temperature,13,10]
Sign = temperature.15
' SEROUT2 GPIO.0,16468, ["SIGN", DEC Sign,13,10]
' SEROUT2 GPIO.0,16468, ["+REMAIN", DEC count_remain,13,10]
' SEROUT2 GPIO.0,16468, ["+PERC", DEC count_per_c,13,10]
PAUSE 2000

if (temperature.HighByte = $FF) and (temperature.LowByte <> 0) then
TempNeg = "-"
temperature = temperature ^ $FFFF
temperature = (((temperature >> 1)*100) - 25 + ((count_per_c + count_remain) * 100) / count_per_c)
if (temperature.HighByte < $FF) and (temperature.LowByte <> 0) then
TempNeg = "+"
temperature = (((temperature >> 1)*100) - 25 + ((count_per_c - count_remain) * 100) / count_per_c)
else
'************************************************
temperature=$0000 ' THIS IS ONLY NEED TO DEFINE !!!
'************************************************
endif
endif
serout2 GPIO.0,16468, ["Temperature: ", TempNeg, DEC (temperature / 100),".", DEC2 temperature, "C ",13,10]
'return
goto Main

end


Thanks for your help,

Scott