Handy Tips - Dallas 1 Wire Protocol

Also see the following projects for more information/examples on 1-Wire Communication;

    1-Wire is a device communications bus system designed by Dallas Semiconductor that provides low-speed data, signaling and power over a single wire (a Ground wire is also needed). 1-Wire is similar in concept to I²C, but with lower data rates and a much lower cost. It is typically used to communicate with small inexpensive devices such as digital thermometers, weather instruments etc.

    Devices are laser programmed with a 64 bit code that contains its unique information. This includes its Family Code, Address Information, and a CRC checksum value for integrity checking. You don't need to use the 64 bit address to talk to most devices when they are the only ones on the databus, however you must when there is more than one.

    To ascertain what 64 bit address a component has, use this example;

Device 16f877
XTAL 4


Declare LCD_TYPE ALPHA              ' Type of LCD Used is Alpha
Declare LCD_DTPIN PORTB.4           ' The control bits B0,B1,B2,B3
Declare LCD_RSPIN PORTB.2           ' RS pin on B4
Declare LCD_ENPIN PORTB.3           ' E pin on B5
Declare LCD_LINES 2                 ' Amount of LCD lines
Declare LCD_INTERFACE 4             ' Interface method is 4 bit

PORTB_PULLUPS = true
ALL_DIGITAL = TRUE

SYMBOL DQ = Portb.0                 ' 1-Wire databus

DIM ID1 AS BYTE
DIM ID2 AS BYTE
DIM ID3 AS BYTE
DIM ID4 AS BYTE
DIM ID5 AS BYTE
DIM ID6 AS BYTE
DIM ID7 AS BYTE
DIM ID8 AS BYTE

Delayms 150

CLS
Again:

OWRITE DQ, 1,[$33]                                ' Request ROM information

OREAD DQ,0,[ID1,ID2,ID3,ID4,ID5,ID6,ID7,ID8]      ' Store the response
Print at 1,1,"Fam= ",HEX2 ID1, " CrC= ", HEX2 ID8
Print at 2,1,"ID= ", HEX2 ID2, HEX2 ID3,HEX2 ID4,HEX2 ID5,HEX2 ID6,HEX2 ID7

Goto Again

 

    Be sure to place the pull-up resistor on the databus. On a side note, I have had problems with 1-Wire data transfer from PORTA, even with the ALL_DIGITAL = TRUE declaration, so I wouldn't recommend any pins on PORTA for 1-Wire data transfer.

Click here to see this circuit in action!

 

 

 Skip Navigation Links.

Collapse Site Tutorial IndexSite Tutorial Index
Expand 16F PIC Examples16F PIC Examples
Expand 18F PIC Examples18F PIC Examples
Collapse Handy TipsHandy Tips
Expand High Power SwitchingHigh Power Switching
Zener Diodes
Photocoupler
OpAmps
Collapse Serial CommsSerial Comms
UART
I2C
SPI
Dallas 1 Wire