1-Wire Communication With PIC Microcontroller: Author: Sashavalli Maniyar Microchip Technology Inc
1-Wire Communication With PIC Microcontroller: Author: Sashavalli Maniyar Microchip Technology Inc
1-Wire Communication With PIC Microcontroller: Author: Sashavalli Maniyar Microchip Technology Inc
VCC VCC
VCC
® I/O DS2411
PIC Microcontroller
1-Wire® Slave Device
GND
OPERATIONS OF THE 1-Wire BUS A communication sequence starts when the bus
master drives a defined length “Reset” pulse that
The four basic operations of a 1-Wire bus are Reset, synchronizes the entire bus. Every slave responds to
Write 0 bit, Write 1 bit and Read bit. the “Reset” pulse with a logic-low “Presence” pulse.
Using these bit operations, one has to derive a byte or To write the data, the master first initiates a time slot by
a frame of bytes. driving the 1-Wire line low, and then, either holds the
The bus master initiates and controls all of the 1-Wire line low (wide pulse) to transmit a logic ‘0’ or releases
communication. Figure 2 illustrates the 1-Wire commu- the line (short pulse) to allow the bus to return to the
nication timing diagram. It is similar to Pulse-Width logic ‘1’ state. To read the data, the master again
Modulation (PWM) because, the data is transmitted by initiates a time slot by driving the line with a narrow low
wide (logic ‘0’) and narrow (logic ‘1’) pulse widths pulse. A slave can then either return a logic ‘0’ by turn-
during data bit time periods or time slots. The timing ing on its open-drain output and holding the line low to
diagram also contains the recommended time values extend the pulse, or return a logic ‘1’ by leaving its
for robust communication across various line open-drain output off to allow the line to recover.
conditions. • Most 1-Wire devices support two data rates:
Table 1 provides a list of operations with descriptions standard speed of about 15 kbps and overdrive
and also implementation steps; this is for standard speed of about 111 kbps.
speed. The protocol is self-clocking and tolerates long inter-bit
delays, which ensures smooth operation in interrupted
software environments.
Master
Sample
Reset
480 μs
550 μs
960 μs
Write 0
Write 1
Read
Master
Sample
Recovery Time
Between Each
Slot
6 μs
15 μs 10 μs
60 μs
Master
Slave
Register
Pull-Up
Example
// Driving the 1-Wire bus low
drive_OW_low();
drive_OW_high
Configures the 1-Wire port pin as an output and drives the port pin to HIGH.
Syntax
void drive_OW_high (void)
Parameter
None
Return Values
None
Precondition
None
Side Effects
None
Example
// Driving the 1-Wire bus High
drive_OW_high();
Example
unsigned char presence_detect ;
Example
// OW_reset_pulse function return the presence pulse from the slave device
if (!OW_reset_pulse())
return HIGH; // Slave Device is detected
else
return LOW; // Slave Device is not detected
Example
unsigned char loop;
Example
unsigned char loop;
unsigned char result = 0;
START
END
Note: The source code provided with this application note contains an implementation of this flowchart which can be customized to your needs.
• Microchip believes that its family of products is one of the most secure families of its kind on the market today, when used in the
intended manner and under normal conditions.
• There are dishonest and possibly illegal methods used to breach the code protection feature. All of these methods, to our
knowledge, require using the Microchip products in a manner outside the operating specifications contained in Microchip’s Data
Sheets. Most likely, the person doing so is engaged in theft of intellectual property.
• Microchip is willing to work with the customer who is concerned about the integrity of their code.
• Neither Microchip nor any other semiconductor manufacturer can guarantee the security of their code. Code protection does not
mean that we are guaranteeing the product as “unbreakable.”
Code protection is constantly evolving. We at Microchip are committed to continuously improving the code protection features of our
products. Attempts to break Microchip’s code protection feature may be a violation of the Digital Millennium Copyright Act. If such acts
allow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that Act.
01/02/08