Timeline
Timeline
2025-12-23
init
This article introduces the basic concepts of the Linux 1-Wire bus, communication steps, and the application of the DS18B20 temperature sensor. It first outlines the protocol features and hardware structure of the 1-Wire bus, which requires only one signal line for bidirectional data transmission, then analyzes the communication timing in master-slave mode, and finally details the performance specifications, pin configuration, and package type of the DS18B20 chip.
Linux Driver Notes
| Table of Contents | Links |
|---|---|
| 1. Linux Driver Framework | |
| 2. Linux Driver Loading Logic | |
| 3. Character Device Basics | |
| 4. Concurrency and Race Conditions | |
| 5. Advanced Character Device Progression | |
| 6. Interrupts | |
| 7. Platform Bus | |
| 8. Device Tree | |
| 9. Device Model | |
| 10. Hot Plug | |
| 11. pinctrl Subsystem | |
| 12. GPIO Subsystem | |
| 13. Input Subsystem | |
| 14. One-Wire Bus | |
| 15. I2C | |
| 16. SPI | |
| 17. UART | |
| 18. PWM | |
| 19. RTC | |
| 20. Watchdog | |
| 21. CAN | |
| 22. Network Device | |
| 23. ADC | |
| 24. IIO | |
| 25. USB | |
| 26. LCD |
Introduction to One-Wire Bus
Overview of One-Wire Bus
One-Wire is a serial communication protocol and hardware bus, used to transmit data and control signals between electronic devices. It was developed by the independent chip manufacturer Dallas Semiconductor and has been widely used in various applications.
Unlike serial data communication methods such as SPI and I2C, the One-Wire bus is characterized byrequiring only one signal line, which can transmit both clock and data, and the data is bidirectional. Therefore, the One-Wire bus has the characteristics of saving I/O pins, simple structure, and ease of expansion and maintenance.
1-Wire is used in various applications, includingtemperature sensors, humidity sensors, EEPROM memory, clocksand so on. It has been widely applied in many fields, such as industrial automation, home automation, the Internet of Things, and electronic device monitoring. This article uses the DS18B20 temperature sensor as an example to learn about 1-Wire.

- Signal Line: 1-Wire uses a single signal line for data transmission and communication. This line is called the data line and also serves as the power supply line. All devices on the 1-Wire bus are connected to this signal line.
- Pull-up Resistor: 1-Wire requires a pull-up resistor connected between the signal line and the power supply to ensure that the signal line remains at a high level (logic 1) when no device is transmitting data. The value of the pull-up resistor is typically between 4.7 kilohms and 10 kilohms. (GPIO set to pull-up)
- Devices: 1-Wire supports multiple devices connected to the signal line. Each device has a unique 64-bit address, which is used to identify and select the target device for communication. Devices can be various types of sensors, memory, clocks, etc.
- Processor: The processor is the controller on the 1-Wire bus. The processor is responsible for sending commands, reading responses, and controlling the slave devices on the 1-Wire bus.
Communication Steps of 1-Wire
1-Wire is amaster-slave structure,**The slave only responds when the master calls it.**Therefore,**the master must strictly follow the command timing of the 1-Wire bus.**If the command timing is incorrect, the device will not respond.
The communication steps of the 1-Wire bus typically include the following phases.
- Initialization: Before communication begins,**the master device sends an initialization signal to ensure no other device is communicating on the 1-Wire bus.**The initialization signal is a specific sequence, typically pulling the data line low for a period and then releasing it.
- ROM Operation Commands
- Function Commands
DS18B20 Introduction
Reference:
Chip Overview
The DS18B20 is a digital temperature sensor chip,Provides temperature measurement with 9 to 12-bit resolution, can beprogrammable non-volatile memory cellsto implement temperature lower and upper limit alarms.
It is a device based on the 1-Wire communication protocol, requiring only one signal wire and one ground wire.
The DS18B20 can measure temperature with high precision, accurate to 0.0625°C. It has a wide measurement range, typically between -55°C and +125°C.
The DS18B20 chip can obtain power from the master device via the 1-Wire bus, or it can be powered by an external power supply. This allows flexible power supply selection in some low-power applications.
Each DS18B20 has a globally unique 64-bit serial number, allowing multiple DS18B20s to be daisy-chained on the same 1-Wire bus for networking. Only one processor is needed to control multiple DS18B20s distributed over a large area. This networking method is particularly suitable for applications such as HVAC environmental control, buildings, equipment, grain temperature measurement, industrial temperature measurement, and process monitoring and control.
Basic Performance
The DS18B20 is a digital temperature sensor chip with the following basic performance characteristics:
- Uses a 1-Wire interface, requiring only one port pin for communication
- Each chip has a globally unique 64-bit serial number
- Has multi-point distributed temperature measurement function without the need for external components
- Can be powered via the data line, with a supply voltage range of 2.5V to 5.5V
- Temperature measurement range is -55°C to +125°C
- Accuracy of ±0.4°C in the range of -10°C to 70°C
- Temperature resolution selectable from 9 to 12 bits
- Temperature conversion time less than 750ms at maximum 12-bit resolution
- User-defined nonvolatile temperature alarm settings
- Alarm search command identifies and flags devices exceeding the programmed temperature
- Strong electrostatic discharge protection: HBM 8000V, MM 800V
- Available in surface-mount MSOP8, SOP8 packages and 3-pin TO-92, TO-92S packages
Pin Configuration and Package
DS18B20 chip pin configuration:
- VDD: Power supply pin, provides positive power to the chip
- DQ: Data pin, used for 1-Wire communication and data transfer
- GND: Ground pin, connects to the chip’s ground (negative power supply)
The DS18B20 chip is available in different package types, with the most common being TO-92 and TO-92-3 packages. These are small three-pin packages suitable for through-hole and surface-mount installation.
The TO-92 package is a common small plastic package with pins arranged in order: VDD, DQ, and GND.
The TO-92-3 package is similar to the TO-92 package but with a slightly different pin order. The pin order for TO-92-3 is GND, DQ, and VDD.
In addition to these common package types, the DS18B20 can also be used in other package types, such as SOT-23 and TO-263 packages, which may have different pin arrangements and sizes. As shown in the figure below:


Internal Structure
The DS18B20 is a digital temperature sensor chip, and its internal structure mainly includes the following components, as shown in the figure below:

- Temperature Sensor: The DS18B20 integrates a temperature sensor internally for measuring ambient temperature. The sensor typically detects temperature based on changes in a reference voltage and converts it into a digital signal.
- A/D Converter: The DS18B20 chip contains an analog-to-digital converter (A/D converter) internally, which is used to convert the analog temperature value measured by the sensor into a corresponding digital representation. This allows temperature data to be processed and transmitted in digital form.
- Memory: The DS18B20 chip also has internal memory for storing configuration information and temperature measurement results. The memory can store a unique 64-bit address, temperature resolution, and other related settings.
- Control Logic: The DS18B20 chip includes control logic circuitry for managing temperature measurement, communication, and other related functions. The control logic coordinates the operation of various parts and communicates with the master device.
- 1-Wire Interface: The DS18B20 uses the 1-Wire communication protocol, and its internal structure includes a data line and a pull-up resistor for communication with the master device. The 1-Wire interface simplifies wiring for connection and communication, allowing multiple DS18B20 sensors to be conveniently daisy-chained on the same bus.
Memory Map
64-Bit Lasered ROM Code

| Part | Meaning |
|---|---|
| 28 | Family Code (DS18B20 fixed as 0x28) |
| FF 1C 46 93 16 03 | Unique Serial Number |
| 5A | CRC Check |
Memory
The memory consists of 9 bytes, allocated as shown in the table below

DS18B20 has built-in CRC check. CRC uses polynomial X⁸ + X⁵ + X⁴ + 1. The host must recalculate the CRC itself. If the two CRCs match → data is correct; if not → indicates communication error. The chip does not automatically prevent errors.
Register Introduction
- Temperature Register: The temperature register stores the result of the most recent temperature measurement. It is a 16-bit register containing the raw data of the temperature value. By reading the data from the temperature register and combining it with the resolution setting, the actual temperature value can be calculated.
- Configuration Register: The configuration register is used to set the operating mode and temperature resolution of the DS18B20. It is an 8-bit register, with each bit corresponding to a configuration option. By writing to the configuration register, you can select the temperature resolution, trigger temperature conversion, and choose the power supply mode, etc.
Configuration Register
The configuration register is used to set the operating mode and temperature resolution of the DS18B20. It is an 8-bit register, with each bit corresponding to a configuration option, as shown in the figure below

Note: The default power-on settings are R0=1, R1=1 (12-bit resolution).
**There is a direct relationship between accuracy and conversion time.**Bits 7 and bits 0 to 4 of the configuration register are reserved by the device and must not be written to. The temperature resolution setting table is as follows:

Temperature Register
The temperature register of the DS18B20 chip is a 16-bit register used to store the raw data of the most recent temperature measurement. The bit layout of the temperature register is as follows:

The least significant bit (LSB) of the temperature register is the bit, indicating a minimum temperature resolution of 0.0625°C. The other bits represent higher temperature resolutions in sequence, as follows:
- (0.125)
- (0.25)
- (0.5)
- (1)
- (2)
- (4)
- (8)
The raw data stored in the temperature register of the DS18B20 chip can be used to calculate the actual temperature value through the following steps:
- The 16-bit data read from the temperature register can be interpreted as a signed integer, where the most significant bit (MSB) represents the sign bit. If the sign bit is 0, it indicates a positive temperature; if the sign bit is 1, it indicates a negative temperature.
- Extract the lower 11 bits (bits 4 to 15) from the temperature register. These bits represent the absolute value of the temperature, where a bit value of 1 indicates that the corresponding temperature resolution is valid.
- Combine these 11 bits of data with the sign bit to form a signed integer.
- Based on the selected temperature resolution,multiply the signed integer by the corresponding resolution factor, to obtain the actual temperature value.
- When the temperature is greater than 0, the sign bit is 0, and the measured temperature value multiplied by the resolution factor gives the actual temperature.
- When the temperature is less than 0, the sign bit is 1, and the measured temperature value is inverted, incremented by one, and then multiplied by the resolution factor to obtain the actual temperature.
For example, suppose a 12-bit temperature resolution is selected, and the data read from the temperature register is 0x1FFF.
The binary representation of 0x1FFF is: 0001 1111 1111 1111. The most significant bit is 0, indicating a positive temperature. Extract the lower 11 bits: 111 1111 1111. Combine these 11 bits with the sign bit to get the signed integer: 0111 1111 1111 (corresponding to 0x07FF).
For a 12-bit temperature resolution, the resolution factor is 0.0625°C. Multiply the signed integer 0x07FF by the resolution factor: 0x07FF * 0.0625 = 127.9375°C.
Therefore, the data 0x1FFF read from the temperature register corresponds to an actual temperature value of approximately 127.94°C.
Instruction Introduction
According to the DS18B20 communication protocol, the host (microcontroller) must go through three steps to control the DS18B20 to complete a temperature conversion:
- A reset operation must be performed on the DS18B20 before each read or write.
- After a successful reset, send a ROM command.
- Finally, send a RAM command to perform the intended operation on the DS18B20.
The reset requires the main CPU to pull the data line low for 500 microseconds, then release it. After the DS18B20 receives the signal, it waits about 16 to 60 microseconds, then sends a presence low pulse lasting 60 to 240 microseconds. When the main CPU receives this signal, it indicates a successful reset.
ROM Command
After the host detects the presence pulse, it can send aROM command. These commands act on the unique64-bit ROM codeof each slave device, allowing the host to select a specific device when multiple devices are present on the 1-Wire bus.
These commands also allow the host to:
- Determine how many devices are on the bus
- Confirm the device type
- Detect if any device has triggered an alarm state
There are a total of5 ROM commands, each command is8 bits long。
Before sending a function command to the DS18B20, the host must first send an appropriate ROM command.
| Instruction | Protocol Code | Function |
|---|---|---|
| Search ROM | F0H | Used to determine the number of DS1820 devices on the same bus and identify the 64-bit ROM address. Prepares for operating each device. |
| Read ROM | 33H | Read the code (i.e., 64-bit address) in the ROM of the DS1820 temperature sensor |
| Match ROM | 55H | After issuing this command, the 64-bit ROM code is then sent to access the DS1820 on the single bus corresponding to that code, making it respond, preparing for subsequent read/write operations on that DS1820. |
| Skip ROM | CCH | Ignore the 64-bit ROM address and directly send a temperature conversion command to the DS1820. Suitable for single-chip operation. |
| Alarm Search | ECH | After execution, only devices whose temperature exceeds the set upper or lower limit will respond. |
Search ROM [F0h]
After system power-up, the host must identify the ROM codes of all slave devices on the bus to know:
- How many devices there are
- The type of each device
The host completes this process using a method of elimination, which requires repeated executionSearch ROM 命令 + 数据交换multiple times until all devices are found.
If there is only one device on the bus, a simpler method can be usedRead ROM [33h]instead of Search ROM.
After each Search ROM process, the host must return to step 1 (initialization) of the communication flow.
Read ROM [33h]
This commandcan only be used when there is only one slave device on the bus。
It allows the host to directly read the 64-bit ROM code of that device without performing the Search ROM process.
If there are multiple devices on the bus and this command is used:
- All devices will respond simultaneously
- Data conflicts will occur
Match ROM [55h]
The host sendsMatch ROM + 64 位 ROM 编码to precisely select a specific device.
Only the device with a fully matching ROM code will respond to subsequent function commands; other devices will wait for the next reset.
Applicable to:
- Multi-device bus
- Single-device bus
Skip ROM [CCh]
This command will:
- Simultaneously select all devices on the bus
- No need to send ROM code
For exampleSkip ROM+Convert T [44h]can make all DS18B20s start temperature conversion simultaneously.
NoteSkip ROM+Read Scratchpad [BEh]Can only be used when there is only one device on the bus.
If there are multiple devices on the bus but this command is used:
- All devices will respond simultaneously
- Data conflicts will occur
Alarm Search [ECh]
This command operates the same way as Search ROM,
but only devices with the alarm flag set will respond. It is used to detect if any device exceeded the alarm threshold during the most recent temperature conversion.
After each Alarm Search process, the master must return to the initialization step.
ROM Commands Timing Diagram

Function Command

Convert T [44h]
This command initiates a temperature measurement.
After conversion is complete:
- The temperature result is written to the 2-byte temperature register in the scratchpad.
- The chip enters a low-power idle state.
If it isparasite power mode:
- the master must, within 10µs after issuing the command,
- enable a strong pull-up.
- Lasts the entire conversion time tCONV
If it isexternal power supply mode:
the host can continuously read time slots:
- Returns 0 → still converting
- Returns 1 → conversion complete
This query cannot be performed in parasitic power mode because the bus is strongly pulled up.
Write Scratchpad [4Eh]
Allows the host to write 3 bytes to the scratchpad:
- 1st byte → TH (byte 2)
- 2nd byte → TL (byte 3)
- 3rd byte → configuration register (byte 4)
Data must:
- LSB first
- All three bytes must be written at once before a reset, otherwise data may be corrupted.
Read Scratchpad [BEh]
The host reads the scratchpad contents:
- Starting from the least significant bit of byte 0
- Read all the way to byte 8 (CRC)
If only partial data is needed:
- You can reset at any time to terminate the read
Copy Scratchpad [48h]
Copy the scratchpad’s:
1 | TH / TL / 配置寄存器 |
Copy to EEPROM.
In parasitic power mode:
- Must enable strong pull-up within 10µs
- Last for at least 10ms
Recall E2 [B8h]
Read from EEPROM:
1 | TH / TL / 配置 |
Reload to scratchpad.
The host can query the status:
- 0 → Restoring
- 1 → Complete
This operation is automatically performed on power-up, so the scratchpad has valid data as soon as power is applied
Read Power Supply [B4h]
Detect power supply method:
Read a time slot after the host sends a command:
- Bus pulled low → Parasitic power
- Bus held high → External power
Function Commands timing diagram

Operation example
Only one DS18B20 on the 1-Wire bus
There is only one DS18B20 on the bus, and it uses parasitic power. The host writes TH, TL, and configuration registers to the DS18B20’s scratchpad, then reads the scratchpad and recalculates the CRC to verify the data. After that, the host copies the scratchpad contents to EEPROM.
| Host mode | Data (LSB first) | Description |
|---|---|---|
| Tx | Reset | Host sends reset pulse |
| Rx | Presence | DS18B20 returns presence pulse |
| Tx | CCh | Host sends Skip ROM (selects all devices on bus) |
| Tx | 4Eh | Host sends Write Scratchpad |
| Tx | 3 bytes of data | Write TH, TL, and configuration registers |
| Tx | Reset | Master resets again |
| Rx | Presence | DS18B20 returns presence pulse |
| Tx | CCh | Skip ROM |
| Tx | BEh | Read Scratchpad |
| Rx | 9 bytes of data | Read scratchpad + CRC and verify |
| Tx | Reset | Master reset |
| Rx | Presence | DS18B20 returns presence pulse |
| Tx | CCh | Skip ROM |
| Tx | 48h | Copy Scratchpad |
| Tx | Strong pull-up ≥ 10ms | Strong pull-up power during EEPROM write |
Multiple DS18B20s on the 1-Wire bus
There are multiple DS18B20s on the bus, and they use parasitic power. The master initiates a temperature conversion for a specified DS18B20, then reads its scratchpad and recalculates the CRC to verify data correctness.
| Master mode | Data (LSB first) | Description |
|---|---|---|
| Tx | Reset | Host sends reset pulse |
| Rx | Presence | DS18B20 returns presence pulse |
| Tx | 55h | Host sends Match ROM command |
| Tx | 64-bit ROM code | Host specifies target DS18B20 |
| Tx | 44h | Host sends Convert T (start temperature measurement) |
| Tx | Strong pull-up to keep high level | Host provides strong pull-up power during the entire conversion time tCONV |
| Tx | Reset | Host sends reset pulse again |
| Rx | Presence | DS18B20 returns presence pulse |
| Tx | 55h | Host sends Match ROM again |
| Tx | 64-bit ROM code | Select the same device again |
| Tx | BEh | Host sends Read Scratchpad |
| Rx | 9 bytes of data | The host reads the scratchpad (including CRC) and calculates the CRC check itself. |
Communication Timing
The DS18B20 uses a strict 1-Wire communication protocol to ensure data integrity. This protocol defines several signal types:
reset pulsepresence pulsewrite 0write 1read 0read 1
All data on the 1-Wire bus is transmitted LSB first (least significant bit first).
Reset Timing
1-WireAll communication on the bus begins with aninitialization sequence.
This initialization sequence includes:
- areset pulse
- sent by the host, followed by apresence pulse
The presence pulse tells the host that there are slave devices (e.g., DS18B20) on the bus and they are ready to communicate.

During initialization:
- The master sends a reset pulse by pulling the 1-Wire bus lowfor at least 480µs
- The master releases the bus and enters receive mode; after release, the bus is pulled high by a 5kΩ pull-up resistor
- The DS18B20 detects the rising edge and waits15µs ~ 60µs
- The DS18B20 sends a presence pulse by pulling the bus low60µs ~ 240µs
- The bus is pulled high by the pull-up resistor (RESISTOR PULLUP)
Read/Write Timing
- The masterwrite time slotwrites data to the DS18B20 during the
- During theread time slot, the master reads data from the DS18B20.
On the 1-Wire bus: each time slot transmits only 1 bit of data.

Write Time Slots
There are two types of write time slots:
- Write 1
- Write 0
Host uses: Write 1 time slot writes logic 1, Write 0 time slot writes logic 0

All write time slots must satisfy:
- Each time slot ≥ 60µs and ≤ 120µs
- Recovery time between adjacent time slots ≥ 1µs
Both write time slots are initiated by the host: first pulling the 1-Wire bus low
Write 1 rule
After the host pulls the bus low: must release within 15µs
After release: the 5kΩ pull-up resistor will pull the bus high
Write 0 rule
- After the host pulls the bus low: maintain low level for ≥ 60µs
DS18B20 will detect the bus state within a sampling window: after the host starts the write time slot,15µs ~ 60µsbetween, if during this time:
- Bus is high → write 1
- Bus is low → write 0
Read Time Slots
DS18B20 Data can only be sent during read slots. So:
- If the master wants to read data, it must actively create read slots
- The slave cannot speak on its own
This is a type of:Master-driven synchronous communication
The master reads immediately after these commands:
- Read Scratchpad [BEh]
- Read Power Supply [B4h]
Additionally, read slots can be used to query status:
- Convert T [44h] (whether temperature conversion is complete)
- Recall E2 [B8h]

Read slots are initiated by the master:
- Master pulls bus low ≥1µs
- Master releases the bus
- DS18B20 sends 0 or 1 within this window
- Send 1 → do nothing → line is pulled up → high level
- Send 0 → actively pull the bus low (DS18B20 releases the bus at the end of the time slot, pull-up resistor restores high level)
EntireRead Slot must be ≥ 60µs long,Recovery between time slots ≥ 1µs
Therefore, DS18B20 data is valid within 15µs after the start of the read time slot, so the host must complete sampling within 15µs

Example
1 |
|

