How often have we said, "I wish I had an extra I/O pin"? Likely more times that we want to admit. Many microcontrollers include serial-communication devices such as UARTs, I2C ports, or SPI ports that communicate with peripheral devices. But those ports require more than one signal line. If you can use 1-Wire communications--developed Dallas Semiconductor--you might eliminate the need for an I2C or SPI port and gain several "extra" I/O pins for other uses.
The 1-Wire communication scheme allows bidirectional half-duplex communications between one master device or MCU, and one or more slave devices. (Yes, you need a ground connection, too.) A 1-Wire device operates at a low data rate--15.4 kbits/sec--but for many external I/O devices such as temperature sensors, ADCs, small EPROMs, timers, and battery monitors that rate suffices. Some 1-Wire devices, though, operate in "overdrive" mode at 125 kbits/sec.
Few MCUs include a 1-Wire interface but you can create one with bit-bashing code that controls timing on a bidirectional I/O pin (see Note below). And you also can create a 1-Wire interface on an FPGA or via an I/O pin on a single-board computer. One-Wire communications can occur over longer distances than those recommended for I2C- or SPI-based devices, so you can use 1-Wire devices as remote sensors. A small MCU, for example, could serve as a remote device that communicates via a 1-Wire line with a host single-board computer. You'd likely need a bidirectional buffer in the remote MCU circuit. For more information on long-distance 1-Wire signaling, read "Guidelines for Reliable Long Line 1-Wire Networks," Application Note 148 at: www.maxim-ic.com/app-notes/index.mvp/id/148.
Choose an MCU and do a Web search for information on 1-Wire code, and I bet you'll find code samples. For example:
"1-Wire Communication with PIC Microcontroller," Application Note 1199. ww1.microchip.com/downloads/en/AppNotes/01199a.pdf.
"1-Wire, The Thermometer." www.avrtutor.com/tutorial/thermo/1wire1.php.
"AVR318: Dallas 1-Wire Master" www.atmel.com/dyn/resources/prod_documents/doc2579.pdf. (A lot of good information here.)
Because Dallas Semiconductor developed the 1-Wire interface, the company--now part of Maxim Integrated Products--has many helpful application notes that relate to 1-Wire communications and interfaces. I recommend:
"1-Wire Communication Through Software," Application Note 126. www.maxim-ic.com/app-notes/index.mvp/id/126
"Interfacing the DS18X20/DS1822 1-Wire Temperature Sensor in a Micro-Controller Environment," Application Note 162. pdfserv.maxim-ic.com/en/an/AN162.pdf.
Maxim also provides an audio-visual "Introduction to 1-Wire Communications" at: www.maxim-ic.com/products/1-wire/flash/overview/index.cfm.
Each factory-made 1-Wire device comes with a unique 56-bit ID code that provides an 8-bit "family code" and a 48-bit serial number. An 8-bit cyclic redundancy-check value gets tacked on the end of this information. So, if you do not know the 64-bit ID information for a given chip, your 1-Wire master must first determine what slave devices connect to the single half-duplex wire. Maxim's "1-Wire Search Algorithm," Application Note 187 provides useful information on how to determine the ID information for attached slave devices. Find that app note at: www.maxim-ic.com/app-notes/index.mvp/id/187.
Some available source code provides only read-and-write code for master or slave devices. To use a 1-Wire device you need a thorough understanding of the communication protocol and how a master device resets, synchronizes, and recognized its attached slave chips. But, that effort will pay off if it gives you those extra one or two must-have I/O pins. --Jon Titus
Note: You can use two pins, one as an output (transmit) line and one as an input (receive) line connected together so your code does not have to reconfigure a single pin as an output and then as an input for half-duplex communications. Read the AVR318 application note mentioned above.
--Jon Titus

