PDA

View Full Version : 1-wire read ROM with 12F675



mosfet
- 23rd October 2007, 11:00
Hello,

I'm trying to get the serial number from a DS18B20 connected to a 12F675 without any success.

There is a 4.7K between VCC and DQ.

Here is the data I get as an output:

Ser# = 000000000000h
CRC Value = 00h
Read ROM...
Read 64-bit device data into the 8-byte array
Family code00h
Ser# = 000000000000h
CRC Value = 00h

I am sure of the DS18B20 (it is working).

Here is the code:

----------------------------------------------------
DEFINE OSC 4

SO CON 0 ' GPIO.0 (Pin7) Serial out
DQ CON 1 ' GPIO.1 (Pin7) one wire data pin "DQ"
SEARCH_ROM CON $F0

ID VAR BYTE[8] ' Array storage variable for 64-bit ROM code

ANSEL=0
OUTPUT DQ

SEROUT2 SO,16468,[13, 10, "1-wire Device Search", 10,13,10,13]

start:
SEROUT2 SO,16468,[ "Read ROM...",10,13]
OWOUT DQ, 1, [$33] ' Issue Read ROM command
SEROUT2 SO,16468,[ "Read 64-bit device data...",10,13]
OWIN DQ, 0, [STR ID\8]' Read 64-bit device data into the 8-byte array "ID"
SEROUT2 SO, 16468,["Family code",HEX2 ID[0],"h", 10, 13]
SEROUT2 SO, 16468,["Ser# = ",HEX2 ID[1],HEX2 ID[2],HEX2 ID[3],HEX2 ID[4],HEX2 ID[5],HEX2 ID[6],"h", 10,13]
SEROUT2 SO, 16468,["CRC Value = ",HEX2 ID[7],"h", 10, 13]
pause 2000
GOTO start

END
----------------------------------------------------

Any idea about why it is not working ?

Thanks,
Fabien

sayzer
- 23rd October 2007, 11:22
Put all these at the beginning of your code.



@ DEVICE pic12F675, INTRC_OSC_NOCLKOUT
@ DEVICE pic12F675, WDT_ON
@ DEVICE pic12F675, PWRT_ON
@ DEVICE pic12F675, MCLR_OFF
@ DEVICE pic12F675, BOD_OFF
@ DEVICE pic12F675, CPD_OFF
@ DEVICE pic12F675, PROTECT_OFF


DEFINE OSCCAL_1K 1 ' osc calibration

CMCON = 7 ' Disable comparators.
VRCON.7 = 0 ' Disable voltage reference module ; no current.
TRISIO = %000000 ' All output except for GP3.
ADCON0.0 = 0 ' Turn off ADC module.
ANSEL = 0 ' Digital I/O.

mosfet
- 23rd October 2007, 13:02
I added:

CMCON = 7 ' Disable comparators.
VRCON.7 = 0 ' Disable voltage reference module ; no current.
TRISIO = %000000 ' All output except for GP3.
ADCON0.0 = 0 ' Turn off ADC module.

... and everything is working properly. THANKS !

Fabien