Skip to content

File syn_soft_onewire.c

FileList > drivers > syn_soft_onewire.c

Go to the source code of this file

Software bit-bang 1-Wire master implementation. More...

  • #include "../util/syn_assert.h"
  • #include "syn_soft_onewire.h"

Public Functions

Type Name
void syn_soft_onewire_init (SYN_SoftOneWire * ow, SYN_GPIO_Pin pin, uint32_t delay_loops)
Initialize a 1-Wire bus instance.
uint8_t syn_soft_onewire_read_byte (const SYN_SoftOneWire * ow)
Read one byte LSB-first from the 1-Wire bus.
void syn_soft_onewire_read_rom (const SYN_SoftOneWire * ow, uint8_t rom)
Read an 8-byte ROM code from the bus (after READ ROM command).
bool syn_soft_onewire_reset (const SYN_SoftOneWire * ow)
Issue a 1-Wire reset pulse and detect device presence.
void syn_soft_onewire_write_byte (const SYN_SoftOneWire * ow, uint8_t byte)
Write one byte LSB-first onto the 1-Wire bus.
void syn_soft_onewire_write_rom (const SYN_SoftOneWire * ow, const uint8_t rom)
Write an 8-byte ROM code to the bus (for MATCH ROM command).

Public Static Functions

Type Name
void ow_delay (const SYN_SoftOneWire * ow, uint32_t us)
NOP-loop delay.
void ow_drive_low (const SYN_SoftOneWire * ow)
Drive the 1-Wire pin low (open-drain).
uint8_t ow_read_bit (const SYN_SoftOneWire * ow)
Read a single bit from the 1-Wire bus.
void ow_release (const SYN_SoftOneWire * ow)
Release the 1-Wire pin (pullup takes over).
void ow_write_bit (const SYN_SoftOneWire * ow, uint8_t bit)
Write a single bit to the 1-Wire bus.

Detailed Description

Timing slots (standard speed): Write-0 slot : drive LOW 60 µs, release 10 µs recovery Write-1 slot : drive LOW 6 µs, release 64 µs recovery Read slot : drive LOW 6 µs, release, sample at ~9 µs, release 55 µs Reset pulse : drive LOW 480 µs, release, detect presence 60–240 µs, total reset cycle ~960 µs

All timing is approximated via a volatile NOP loop (delay_loops per µs). All I/O uses syn_port_gpio: output = drive low, input = release/read.

Public Functions Documentation

function syn_soft_onewire_init

Initialize a 1-Wire bus instance.

void syn_soft_onewire_init (
    SYN_SoftOneWire * ow,
    SYN_GPIO_Pin pin,
    uint32_t delay_loops
) 

Parameters:


function syn_soft_onewire_read_byte

Read one byte LSB-first from the 1-Wire bus.

uint8_t syn_soft_onewire_read_byte (
    const SYN_SoftOneWire * ow
) 

Parameters:

  • ow Initialized bus handle.

Returns:

Byte received.


function syn_soft_onewire_read_rom

Read an 8-byte ROM code from the bus (after READ ROM command).

void syn_soft_onewire_read_rom (
    const SYN_SoftOneWire * ow,
    uint8_t rom
) 

Parameters:

  • ow Initialized bus handle.
  • rom Output buffer, must be at least 8 bytes.

function syn_soft_onewire_reset

Issue a 1-Wire reset pulse and detect device presence.

bool syn_soft_onewire_reset (
    const SYN_SoftOneWire * ow
) 

Parameters:

  • ow Initialized bus handle.

Returns:

true if at least one device acknowledged (presence pulse detected), false if the bus is empty.


function syn_soft_onewire_write_byte

Write one byte LSB-first onto the 1-Wire bus.

void syn_soft_onewire_write_byte (
    const SYN_SoftOneWire * ow,
    uint8_t byte
) 

Parameters:

  • ow Initialized bus handle.
  • byte Byte to transmit.

function syn_soft_onewire_write_rom

Write an 8-byte ROM code to the bus (for MATCH ROM command).

void syn_soft_onewire_write_rom (
    const SYN_SoftOneWire * ow,
    const uint8_t rom
) 

Parameters:

  • ow Initialized bus handle.
  • rom 8-byte ROM code, LSB first.

Public Static Functions Documentation

function ow_delay

NOP-loop delay.

static void ow_delay (
    const SYN_SoftOneWire * ow,
    uint32_t us
) 

Parameters:

  • ow 1-Wire instance.
  • us Microseconds to delay.

function ow_drive_low

Drive the 1-Wire pin low (open-drain).

static void ow_drive_low (
    const SYN_SoftOneWire * ow
) 

Parameters:

  • ow 1-Wire instance.

function ow_read_bit

Read a single bit from the 1-Wire bus.

static uint8_t ow_read_bit (
    const SYN_SoftOneWire * ow
) 

Parameters:

  • ow 1-Wire instance.

Returns:

Bit value (0 or 1).


function ow_release

Release the 1-Wire pin (pullup takes over).

static void ow_release (
    const SYN_SoftOneWire * ow
) 

Parameters:

  • ow 1-Wire instance.

function ow_write_bit

Write a single bit to the 1-Wire bus.

static void ow_write_bit (
    const SYN_SoftOneWire * ow,
    uint8_t bit
) 

Parameters:

  • ow 1-Wire instance.
  • bit Bit value (0 or 1).


The documentation for this class was generated from the following file src/syntropic/drivers/syn_soft_onewire.c