Skip to main content

Module onewire

Module onewire 

Source
Expand description

The 1-Wire bus: one data line, a pull-up resistor, and strict timing.

A 1-Wire device such as the DS18B20 shares a single open-drain line with the controller and any number of other devices. The controller drives the line low for fixed intervals and releases it for the pull-up to raise; the device answers by holding the line low inside windows the controller samples. Everything on the bus is built from three primitives, and OneWireBus names them: a reset pulse that every device answers with a presence pulse, a write slot that carries one bit, and a read slot that samples one bit. BitBang implements them over any pin that can be driven low and read back, plus a delay, so a microcontroller runs the bus from one GPIO with no peripheral at all.

Above the primitives sit the ROM commands every 1-Wire device understands, the 64-bit RomCode that identifies each one (an 8-bit family code, a 48-bit serial, and a CRC-8), and the Search that enumerates every device on a bus one ROM code at a time. The slot and reset timings are the ones the DS18B20 datasheet specifies, and they match the timings the Linux kernel’s w1 bus driver uses for a bit-banged controller.

Bit-banging needs microsecond-accurate delays, which a microcontroller has and a Linux process does not. On a Raspberry Pi use the kernel’s own w1-gpio driver and read a thermometer through the sysfs file it exposes; the DS18B20 driver in pamoja-sensors covers both paths.

Modules§

command
The ROM commands every 1-Wire device answers, issued right after a reset.
timing
The bus timings in microseconds, from the DS18B20 datasheet’s slot definitions.

Structs§

BitBang
A 1-Wire controller bit-banged over one open-drain pin and a delay.
RomCode
The 64-bit identity every 1-Wire device carries: family, serial, and CRC.
Search
Enumerates the devices on a bus, one ROM code per call.

Enums§

OneWireError
What can go wrong above the pin: the bus protocol itself.

Traits§

OneWireBus
A 1-Wire bus: the three signaling primitives, and the byte and ROM operations built on them.

Functions§

crc8
Computes the Maxim 1-Wire CRC-8 over data.