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

Non-blocking DS2413 dual-channel addressable switch driver. More...

#include "ow_config.h"
#include "ow_version.h"
#include <stdint.h>

Go to the source code of this file.

Macros

#define DS2413_FAMILY_CODE   0x3Au
 DS2413 1-Wire family code (LSB of the 64-bit ROM address).
#define DS2413_ROM_BYTES   8u
 Number of bytes in a device ROM address.
#define DS2413_BITS_PER_BYTE   8u
 Standard 8 bits per byte.
#define DS2413_PIOA   0x01u
 PIOA channel bit in a state byte.
#define DS2413_PIOB   0x02u
 PIOB channel bit in a state byte.
#define DS2413_PIO_MASK   0x03u
 Both PIO channels.
#define DS2413_CMD_READ   0xF5u
 PIO Access Read command.
#define DS2413_CMD_WRITE   0x5Au
 PIO Access Write command.
#define DS2413_ACK   0xAAu
 Acknowledge byte returned by a successful PIO Access Write.
#define DS2413_NO_RESPONSE   0xFFu
 Reply byte when the device did not answer.

Functions

void ds2413_init (void)
 Initialize the DS2413 driver hardware.
void ds2413_select (const uint8_t *rom)
 Select the DS2413 to address.
uint8_t ds2413_read_pio (uint8_t *out)
 Read the PIO pin levels (non-blocking).
uint8_t ds2413_read_pio_poll (void)
 Advance the non-blocking PIO read.
uint8_t ds2413_write_pio (uint8_t states)
 Write the PIO output latches (non-blocking).
uint8_t ds2413_write_pio_poll (void)
 Advance the non-blocking PIO write.
uint8_t ds2413_last_command_ok (void)
 Result of the last completed operation.
uint8_t ds2413_last_pio (void)
 Last valid PIO pin levels read by ds2413_read_pio().
uint8_t ds2413_last_latches (void)
 Last valid PIO latch states read by ds2413_read_pio().
uint8_t ds2413_last_reply (void)
 Raw reply byte of the last read or write operation.

Detailed Description

Non-blocking DS2413 dual-channel addressable switch driver.

The DS2413 has two open-drain PIO pins (PIOA, PIOB). A write sets both output latches; a read returns the actual pin levels and the latches separately (the pin equals its latch when the pin is not driven externally). The device is parasite powered: the driver primes it with a 1 ms strong pull-up before each operation, then releases the bus for the reset/command/reply sequence. A failed reply is retried up to three times.

The driver follows the same non-blocking start/poll discipline as the DS18B20 and DS2431 drivers and shares the TIM1/DMA/GPIO bus with them: one operation at a time, no concurrent polling of two drivers.

Wire protocol (DS2413 datasheet, also used by the Linux w1_ds2413 driver):

  • PIO Access Read [F5h]: one reply byte; in the low nibble bit 0 is the PIOA pin, bit 1 the PIOA latch, bit 2 the PIOB pin and bit 3 the PIOB latch; bits 4-7 are its complement. 0xFF means the device did not answer; a byte whose low nibble is not the complement of its high nibble is rejected. The driver normalizes both halves to the write layout (bit 0 = PIOA, bit 1 = PIOB): pins in ds2413_last_pio() / the read destination, latches in ds2413_last_latches().
  • PIO Access Write [5Ah]: the master sends the state byte (bits 0/1 are PIOA/PIOB, bits 2-7 must be 1) followed by its complement, then reads one acknowledge byte. 0xAA means the write was accepted.

Addressing: ds2413_select() chooses Match ROM (0x55 + 8-byte ROM) for one device or Skip ROM (0xCC) for a broadcast. Broadcast write is useful to set several switches at once. Broadcast read is allowed but only meaningful with a single DS2413 on the bus: several devices answering at once produce a wired-AND of their replies, which the driver cannot attribute.