stm32-async-1wire 3.2.0
Non-blocking 1-Wire master for STM32 with DS18B20 temperature and DS2431 EEPROM drivers
Loading...
Searching...
No Matches
DS18B20 Non-Blocking Command Transactions

Infrequent DS18B20 commands driven with the same non-blocking discipline as the device search and the resolution change: every command owns TIM1/DMA while it runs (reset -> presence -> write -> read | wait) and leaves the bus idle when done. More...

Functions

void ds18b20_read_rom (uint8_t *rom)
 Read the 64-bit ROM of the (only) DS18B20 on the bus.
uint8_t ds18b20_read_rom_poll (void)
 Advance the non-blocking Read ROM transaction.
void ds18b20_set_alarm_thresholds (uint8_t th, uint8_t tl)
 Configure the alarm trigger thresholds TH and TL.
uint8_t ds18b20_set_alarm_thresholds_poll (void)
 Advance the non-blocking alarm threshold write.
void ds18b20_read_scratchpad (uint8_t *buf)
 Read the 9-byte scratchpad (raw; includes TH, TL and the CRC).
uint8_t ds18b20_read_scratchpad_poll (void)
 Advance the non-blocking raw scratchpad read.
void ds18b20_copy_scratchpad (void)
 Copy the scratchpad into the EEPROM (non-volatile).
uint8_t ds18b20_copy_scratchpad_poll (void)
 Advance the non-blocking Copy Scratchpad transaction.
void ds18b20_recall_eeprom (void)
 Recall the EEPROM contents into the scratchpad.
uint8_t ds18b20_recall_eeprom_poll (void)
 Advance the non-blocking Recall EEPROM transaction.
void ds18b20_set_parasite (uint8_t parasite)
 Declare the bus as parasite-powered.
void ds18b20_detect_parasite (void)
 Detect the bus wiring and configure parasite mode automatically.
uint8_t ds18b20_detect_parasite_poll (void)
 Advance the non-blocking parasite-mode detection.
uint8_t ds18b20_parasite_mode (void)
 Current parasite-power configuration of the driver.
uint8_t ds18b20_last_command_ok (void)
 Result of the last completed command transaction.

Detailed Description

Infrequent DS18B20 commands driven with the same non-blocking discipline as the device search and the resolution change: every command owns TIM1/DMA while it runs (reset -> presence -> write -> read | wait) and leaves the bus idle when done.

Each command is a start/poll pair; poll until it returns 1, then call ds18b20_start_measure() to measure again. Commands are ignored mid-cycle, while a device search or a resolution change runs, or while another command transaction is still running. Result buffers passed to the read commands must stay valid until the transaction finishes.

Function Documentation

◆ ds18b20_copy_scratchpad()

void ds18b20_copy_scratchpad ( void )

Copy the scratchpad into the EEPROM (non-volatile).

Note
The copy draws its supply from VDD on externally powered devices; parasite-powered devices are supplied by the strong pull-up, which the driver engages for the t_COPY hold-off window when ds18b20_set_parasite(1) is set. The driver waits the datasheet hold-off (10ms) before finishing.

◆ ds18b20_copy_scratchpad_poll()

uint8_t ds18b20_copy_scratchpad_poll ( void )

Advance the non-blocking Copy Scratchpad transaction.

Returns
1 when finished (successfully or aborted), 0 while running

◆ ds18b20_detect_parasite()

void ds18b20_detect_parasite ( void )

Detect the bus wiring and configure parasite mode automatically.

Note
Runs a Read Power Supply transaction (current addressing) and, on success, stores the decoded answer into the driver state as if ds18b20_set_parasite() had been called with it. On abort (no device present) the flag is left untouched. Call once after ds18b20_init() before the first conversion. On a mixed bus (externally powered devices alongside parasite-powered ones) the open-drain answer is a wired-AND: any externally powered device masks the parasite report, so run the detection per-device in MATCH-ROM addressing mode for heterogeneous wiring.

◆ ds18b20_detect_parasite_poll()

uint8_t ds18b20_detect_parasite_poll ( void )

Advance the non-blocking parasite-mode detection.

Returns
1 when finished (successfully or aborted), 0 while running; check ds18b20_last_command_ok() and ds18b20_parasite_mode() after

◆ ds18b20_last_command_ok()

uint8_t ds18b20_last_command_ok ( void )

Result of the last completed command transaction.

Returns
1 when the last ds18b20_*_poll() finished a transaction that found a device present (and, for read commands, read its data back), 0 when it aborted (e.g. no device present) or nothing ran yet

◆ ds18b20_parasite_mode()

uint8_t ds18b20_parasite_mode ( void )

Current parasite-power configuration of the driver.

Returns
1 when the strong pull-up will be engaged during conversion and EEPROM programming windows, 0 for external VDD supply

◆ ds18b20_read_rom()

void ds18b20_read_rom ( uint8_t * rom)

Read the 64-bit ROM of the (only) DS18B20 on the bus.

Parameters
[in,out]romBuffer for the 8-byte ROM (LSB first); written on success
Note
Valid only when exactly one device is on the bus (datasheet Read ROM 0x33). With several devices use the non-blocking device search (ds18b20_search_*).
Result validity: check ds18b20_last_command_ok() or the CRC over the 7 leading bytes (ds18b20_crc8(rom, 7) == rom[7]).

◆ ds18b20_read_rom_poll()

uint8_t ds18b20_read_rom_poll ( void )

Advance the non-blocking Read ROM transaction.

Returns
1 when finished (successfully or aborted), 0 while running

◆ ds18b20_read_scratchpad()

void ds18b20_read_scratchpad ( uint8_t * buf)

Read the 9-byte scratchpad (raw; includes TH, TL and the CRC).

Parameters
[in,out]bufBuffer for the 9 scratchpad bytes (byte 0 = temp LSB, bytes 2/3 = TH/TL, byte 8 = CRC); written on success
Note
Result validity: check ds18b20_last_command_ok() or the CRC over the 8 leading bytes (buf[8] == ds18b20_crc8(buf, 8)).

◆ ds18b20_read_scratchpad_poll()

uint8_t ds18b20_read_scratchpad_poll ( void )

Advance the non-blocking raw scratchpad read.

Returns
1 when finished (successfully or aborted), 0 while running
Note
On a valid read (CRC byte matches) the conversion resolution is auto-derived from the config byte (byte 4), like the measurement path.

◆ ds18b20_recall_eeprom()

void ds18b20_recall_eeprom ( void )

Recall the EEPROM contents into the scratchpad.

Note
Loads the last EEPROM copy (TH/TL/CFG) into the volatile scratchpad. The driver waits the datasheet t_RECALL hold-off (10ms) before finishing.

◆ ds18b20_recall_eeprom_poll()

uint8_t ds18b20_recall_eeprom_poll ( void )

Advance the non-blocking Recall EEPROM transaction.

Returns
1 when finished (successfully or aborted), 0 while running

◆ ds18b20_set_alarm_thresholds()

void ds18b20_set_alarm_thresholds ( uint8_t th,
uint8_t tl )

Configure the alarm trigger thresholds TH and TL.

Parameters
[in]thHigh-alarm trigger value (DS18B20 8-bit threshold code)
[in]tlLow-alarm trigger value (DS18B20 8-bit threshold code)
Note
Uses the DS18B20 8-bit sign-extended temperature code, the same encoding the scratchpad TH/TL bytes use; converting to/from Celsius is left to the application. The current conversion resolution (byte 4, R1/R0) is written unchanged, so the resolution is not disturbed.
Takes effect immediately in the scratchpad; run ds18b20_copy_scratchpad() afterwards to persist TH/TL/CFG to the EEPROM.

◆ ds18b20_set_alarm_thresholds_poll()

uint8_t ds18b20_set_alarm_thresholds_poll ( void )

Advance the non-blocking alarm threshold write.

Returns
1 when finished (successfully or aborted), 0 while running

◆ ds18b20_set_parasite()

void ds18b20_set_parasite ( uint8_t parasite)

Declare the bus as parasite-powered.

Parameters
[in]parasite1 = devices are powered over the data line, 0 = external VDD supply (default)
Note
In parasite mode the driver engages the strong pull-up (bus pin switched to push-pull HIGH) for every temperature conversion window (t_CONV, up to 750ms) and EEPROM programming hold-off (t_COPY / t_RECALL), then releases the line back to the passive pull-up before any further bus activity. Call once after ds18b20_init() or between measurement cycles; applies to all subsequent operations. Use ds18b20_detect_parasite() to detect the wiring first.