1-Wire
This section refers to the following sample application(s):
02-onewire
1-Wire is a well-known protocol used for communicating between a micro-controller and one or more sensor/actuator 1-Wire slave devices, using a single data wire. Some 1-Wire devices also harvest energy from the data wire, so they don't require any other power source. This makes it a popular protocol for interfacing to simple sensors (e.g. temperature, humidity), and several vendors sell sensors with a 1-Wire interface.
Communication over the data wire is bi-directional. An external pull-up resistor is used to pull the data wire high by default. The 1-Wire protocol defines how the master and the slaves communicate using a combination of timeouts, GPIO-like reads and pull-down operations. Each 1-Wire device has a unique 64-bit address. The procedures for discovering the addresses of the 1-Wire devices connected to the bus, and for reading and writing arbitrary data to a specific 1-Wire slave are all built into the protocol.
A typical 1-Wire transaction consists of the following steps:
- A "detection" step during the which the master pulls down the data (called the "reset pulse"). A certain timeout after the master releases the bus, a slave will also pull the data line down (the "presence pulse"). When the master sees the data line being low after it released it, the master knows that there is at least one device on the bus.
- An "addressing" step during which the master sends a command indicating the type of addressing to be used, sometimes followed by the 64-bit address of the slave to communicate with. Typical commands are detailed below.
- One or more "communication" steps during which the master can transmit an arbitrary number of bytes to the addressed slave, or read an arbitrary number of bytes from it.
Name | Value | Description |
---|---|---|
READ_ROM | 0x33 | Indicates to the slave that it should transmit its 64-bit address during the next read operation. This can only be used if a single device is present on the bus. |
SEARCH_ROM | 0xFE | Indicates to the slaves that the master will start a "search" operation to determine the 64-bit addresses of the devices on the bus. This search operation consists of single-bit write and read operations to efficiently "walk" the 64-bit addressing space. |
MATCH_ROM | 0x55 | Indicates that the master will send the 64-bit address of the slave it wishes to communicate with. |
SKIP_ROM | 0xCC | Indicates that the master wishes to skip the addressing step and start communicating right away.This command can only be used if a single slave device is present on the bus. |
1-Wire on the LTC5800
The
LTC5800
chip has built-in 1-Wire support. Your application has access to three 1-Wire devices, each corresponding to a different pin, as listed in the following table:1-Wire device | silkscreen on the board |
---|---|
DN_1WIRE_UART_DEV_ID | TX |
DN_1WIRE_UARTC0_DEV_ID | C0 TX |
DN_1WIRE_UARTC1_DEV_ID | S MISO |
We discourage the use of DN_1WIRE_UARTC0_DEV_ID
as a 1-Wire device since it prevents you from using the CLI interface.
Refer to the
SmartMesh On-Chip API html documentation
in the /doc
directory of the for documentation about this feature.
The 02-onewire
Sample Application
The 02-onewire
sample application defines a number of CLI commands to perform 1-Wire operations. The OWI_DEVICE
define sets the 1-Wire device to be used. When set to DN_1WIRE_UARTC1_DEV_ID
(the default value), the pin corresponding to the 1-Wire data line is labeled S MISO
on the
This sample application does not define any additional tasks (operations are done directly in the CLI's task), nor does it attempt to join a network.
To be able to run this sample application, you need to connect a 1-Wire slave device to your
as follows:- Connect your 1-Wire slave's ground line to a pin labeled
GND
on the silkscreen. - Connect your 1-Wire slave's data line to the pin labeled
MISO
on the silkscreen. - Use a resistor to pull the data line high by connecting it between the data line and the labeled
Vsupply
on the silkscreen. The value of this resistor is typically 5k Ohm, although you should find the recommended value in the datasheet of your 1-Wire slave.
After programming the
, use the following CLI commands to trigger 1-Wire operations:Command | |
---|---|
d | The "detect" command will issue a reset pulse and listen for a presence pulse. The CLI interface will print whether at least one 1-Wire slave device is present on the bus. |
w | The "write" command allows you write arbitrary data over the 1-Wire data line. The payload you enter must be written in hexadecimal characters. That is, entering
issues the |
wb | The "write bit" command allows you to write a single bit to the 1-Wire data line. You need to specify a single argument, either 0 or 1 . |
r | The "read" command allows you to read an arbitrary number of bytes from the 1-Wire bus. You need to specify the number of bytes (in decimal) as the only argument. That is, entering
reads 8 bytes. |
rb | The "read bit" command allows you to read a single bit from the 1-Wire bus. After entering this command, the CLI interface prints the bit read, either 0 or 1 . |
s | The "search" command performs a 1-Wire search operation, and prints the 64-bit addresses of the devices present on the bus. You can use the information gathered by this operation to address a specific device in a subsequent transaction. |
In the following (annotated) screenshot, a single device is connected to the 1-Wire data bus. The following commands read the 64-bit address of that device using the READ_ROM
command:
///=== Transaction 1 > d /// detect the presence of a device slavePresent=1 > w 33 /// issue the READ_ROM command > r 8 /// read 8 bytes (8 bytes) 01 03 9b ac 15 00 00 67
In the following (annotated) screenshot, a second device is connected to the same 1-Wire data bus. The search command is used to discover its address. That information is then used to read/write data from that device.
///=== Transaction 1 > d /// detect the presence of a device slavePresent=1 > s /// search and print the 64-bit addresses found 2 device(s) - (8 bytes) 24 80 4a 38 00 00 00 f1 - (8 bytes) 01 03 9b ac 15 00 00 67 ///=== Transaction 2 > d /// detect the presence of a device slavePresent=1 > w 55 /// write the MATCH_ROM command > w 24804a38000000f1 /// indicate the address of the slave > w 99 /// write some command to that slave > w 0b00000000 /// write more to that slave ///=== Transaction 3 > d /// detect the presence of a device slavePresent=1 > w 55 /// write the MATCH_ROM command > w 24804a38000000f1 /// write the MATCH_ROM command > w 66 /// write some command to that slave > r 5 /// read some data from that slave (5 bytes) 0c 0b 00 00 00