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

Functions

void ds2431_init (void)
 Initialize DS2431 driver hardware and peripherals.
void ds2431_select (const uint8_t *rom)
 Select which DS2431 device to address by its ROM address.
void ds2431_set_parasite (uint8_t parasite)
 Declare the bus as parasite-powered.
uint8_t ds2431_parasite_mode (void)
 Current parasite-power configuration of the driver.
uint8_t ds2431_last_command_ok (void)
 Result of the last completed DS2431 operation.
void ds2431_read_memory (uint8_t *dst, uint16_t addr, uint8_t len)
 Read up to DS2431_READ_PASS bytes of EEPROM (non-blocking).
uint8_t ds2431_read_memory_poll (void)
 Advance the non-blocking Read Memory operation.
uint8_t ds2431_write_scratchpad (uint16_t addr, const uint8_t *data, uint8_t len)
 Write up to 8 bytes into the scratchpad (non-blocking).
uint8_t ds2431_write_scratchpad_poll (void)
 Advance the non-blocking Write Scratchpad operation.
void ds2431_read_scratchpad (uint8_t *buf)
 Read the scratchpad frame (non-blocking).
uint8_t ds2431_read_scratchpad_poll (void)
 Advance the non-blocking scratchpad frame read.
void ds2431_copy_scratchpad (void)
 Copy the scratchpad into the EEPROM (non-blocking).
uint8_t ds2431_copy_scratchpad_poll (void)
 Advance the non-blocking Copy Scratchpad operation.

Detailed Description

Function Documentation

◆ ds2431_copy_scratchpad()

void ds2431_copy_scratchpad ( void )

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

Note
Programs the EEPROM block selected by the last Write Scratchpad (target address + ES). The driver waits the t_PROG hold-off (11ms), holds the strong pull-up for the whole window in parasite mode, then reads the device's completion pattern and sets the success flag only for 0xAA (logic 1 = the device refused the copy: PF set, invalid address or copy-protected page). Ignored unless a Write Scratchpad completed since the last reset/select.

◆ ds2431_copy_scratchpad_poll()

uint8_t ds2431_copy_scratchpad_poll ( void )

Advance the non-blocking Copy Scratchpad operation.

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

◆ ds2431_init()

void ds2431_init ( void )

Initialize DS2431 driver hardware and peripherals.

Precondition
Call after MCU reset, after the system clock is configured and before any 1-Wire bus operation.
Note
Calls onewire_init(), which takes exclusive ownership of the shared TIM1/DMA/GPIO resources for the lifetime of the driver (until reset). The DS18B20 and DS2413 drivers share that bus: all three driver inits may run before any bus operation (each onewire_init() re-applies the same idle configuration), and the drivers may then be used alternately, one operation at a time, as examples/9_multi does. Concurrent polling of the drivers is unsupported.
Warning
A second call does not stop an active operation and does not fully reset the timer, DMA, low-power or DS2431 software state.

◆ ds2431_last_command_ok()

uint8_t ds2431_last_command_ok ( void )

Result of the last completed DS2431 operation.

Returns
1 when the last ds2431_*_poll() finished an operation that found a device present (and, for reads, verified its data - for Copy Scratchpad, the device's 0xAA completion pattern), 0 when it aborted (e.g. no device present, a scratchpad echo mismatch, a refused copy) or nothing ran yet

◆ ds2431_parasite_mode()

uint8_t ds2431_parasite_mode ( void )

Current parasite-power configuration of the driver.

Returns
1 when the strong pull-up will be engaged during the t_PROG programming window, 0 for external VDD supply

◆ ds2431_read_memory()

void ds2431_read_memory ( uint8_t * dst,
uint16_t addr,
uint8_t len )

Read up to DS2431_READ_PASS bytes of EEPROM (non-blocking).

Parameters
[in,out]dstBuffer for the read data; written on success
[in]addrStart address in EEPROM (0 .. DS2431_EEPROM_SIZE - 1)
[in]lenBytes to read, 1 .. DS2431_READ_PASS; addr + len must not exceed DS2431_EEPROM_SIZE
Note
Issues a Read Memory (0xF0) command from addr. Result validity: check ds2431_last_command_ok() after the poll reports 1. Out-of-range requests are ignored. Large regions are read in repeated passes.

◆ ds2431_read_memory_poll()

uint8_t ds2431_read_memory_poll ( void )

Advance the non-blocking Read Memory operation.

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

◆ ds2431_read_scratchpad()

void ds2431_read_scratchpad ( uint8_t * buf)

Read the scratchpad frame (non-blocking).

Parameters
[in,out]bufBuffer for TA1, TA2, ES and the scratchpad bytes; written on success. The caller reads the real data length from the E/S byte (buf[2] & 0x07); bytes beyond the reply window are zeroed, so the buffer is always DS2431_SCRATCH_FRAME long.
Note
The device returns (E[2:0] - T[2:0] + 1) data bytes: the driver clocks the maximum reply and verifies the inverted CRC-16 over what was actually transmitted. When a Write Scratchpad completed since the last reset/select, the driver verifies the echoed TA1/TA2/ES against the latched values, rejects a set PF flag (incomplete write) and compares the read-back data with the payload that was sent; it clears the success flag on any mismatch (ds2431_last_command_ok() reports 0). Without a pending write there is nothing to compare against, so the frame is returned with the flag set from presence.

◆ ds2431_read_scratchpad_poll()

uint8_t ds2431_read_scratchpad_poll ( void )

Advance the non-blocking scratchpad frame read.

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

◆ ds2431_select()

void ds2431_select ( const uint8_t * rom)

Select which DS2431 device to address by its ROM address.

Parameters
[in]romPointer to the 8-byte ROM address (LSB first), or NULL to return to Skip ROM (broadcast) addressing
Note
With a non-NULL address the driver sends Match ROM (0x55) plus the device address before every command, so only that device responds. The address should come from a family-filtered device search (onewire_search_start(sink, max, ONEWIRE_SEARCH_ROM, DS2431_FAMILY_CODE)).
Applies only while the driver is idle. A select() clears the latched write-cycle state (pending TA/ES): address the same device for the whole write_scratchpad -> read_scratchpad -> copy_scratchpad cycle.

◆ ds2431_set_parasite()

void ds2431_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
Drives the DS2431 EEPROM programming hold-off (t_PROG) through the strong pull-up (bus pin switched to push-pull HIGH), then releases the line back to the passive pull-up. Call once after ds2431_init() or between operations; applies to all subsequent Copy Scratchpad runs.

◆ ds2431_write_scratchpad()

uint8_t ds2431_write_scratchpad ( uint16_t addr,
const uint8_t * data,
uint8_t len )

Write up to 8 bytes into the scratchpad (non-blocking).

Parameters
[in]addrBlock-aligned target address in EEPROM
[in]dataData to write to the scratchpad
[in]lenBytes to write, 1 .. DS2431_SCRATCH_SIZE; addr + len must not exceed DS2431_EEPROM_SIZE
Returns
1 if the Write Scratchpad was scheduled, 0 if the request was rejected (NULL data, len out of range, addr + len beyond the EEPROM, addr not 8-byte aligned, or an operation is already in flight / a search is running)
Note
The EEPROM is programmed in 8-byte blocks: addr must be 8-byte aligned (a misaligned addr is rejected) and len should be the full block. A shorter len leaves the remaining scratchpad bytes stale, sets the device's PF flag, and Copy Scratchpad then refuses the block; the driver reports that as a failure (ds2431_read_scratchpad() and ds2431_copy_scratchpad() both clear the success flag). The write only fills the volatile scratchpad; run ds2431_read_scratchpad() to verify and ds2431_copy_scratchpad() to program the EEPROM.

◆ ds2431_write_scratchpad_poll()

uint8_t ds2431_write_scratchpad_poll ( void )

Advance the non-blocking Write Scratchpad operation.

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