OneWire-UART

group OW

OneWire API.

Note

Functions with _raw suffix do no implement locking mechanism when used with operating system.

Defines

OW_UNUSED(x)

Unused variable macro

OW_ASSERT(msg, c)

Assert check function.

It returns owPARERR if condition check fails

Parameters
  • [in] msg: Optional message parameter to print on failure

  • [in] c: Condition to check for

OW_ASSERT0(msg, c)

Assert check function with return 0

It returns 0 if condition check fails

Parameters
  • [in] msg: Optional message parameter to print on failure

  • [in] c: Condition to check for

OW_ARRAYSIZE(x)

Get size of statically declared array.

Return

Number of array elements

Parameters
  • [in] x: Input array

OW_CMD_RSCRATCHPAD

Read scratchpad command for 1-Wire devices

OW_CMD_WSCRATCHPAD

Write scratchpad command for 1-Wire devices

OW_CMD_CPYSCRATCHPAD

Copy scratchpad command for 1-Wire devices

OW_CMD_RECEEPROM

Read EEPROM command

OW_CMD_RPWRSUPPLY

Read power supply command

OW_CMD_SEARCHROM

Search ROM command

OW_CMD_READROM

Read ROM command

OW_CMD_MATCHROM

Match ROM command. Select device with specific ROM

OW_CMD_SKIPROM

Skip ROM, select all devices

Typedefs

typedef owr_t (*ow_search_cb_fn)(ow_t *const ow, const ow_rom_t *const rom_id, size_t index, void *arg)

Search callback function implementation.

Return

owOK on success, member of owr_t otherwise

Parameters
  • [in] ow: 1-Wire handle

  • [in] rom_id: Rom address when new device detected. Set to NULL when search finished

  • [in] index: Current device index When rom_id = NULL, value indicates number of total devices found

  • [in] arg: Custom user argument

Enums

enum owr_t

1-Wire result enumeration

Values:

owOK = 0x00

Device returned OK

owERRPRESENCE

Presence was not successful

owERRNODEV

No device connected, maybe device removed during scan?

owERRTXRX

Error while exchanging data

owERRBAUD

Error setting baudrate

owPARERR

Parameter error

owERR

General-Purpose error

Functions

owr_t ow_init(ow_t *const ow, const ow_ll_drv_t *const ll_drv, void *arg)

Initialize OneWire instance.

Return

owOK on success, member of owr_t otherwise

Parameters
  • [in] ow: OneWire instance

  • [in] ll_drv: Low-level driver

  • [in] arg: Custom argument

void ow_deinit(ow_t *const ow)

Deinitialize OneWire instance.

Parameters
  • [in] ow: OneWire instance

owr_t ow_protect(ow_t *const ow, const uint8_t protect)

Protect 1-wire from concurrent access.

Note

Used only for OS systems

Return

owOK on success, member of owr_t otherwise

Parameters
  • [inout] ow: 1-Wire handle

  • [in] protect: Set to 1 to protect core, 0 otherwise

owr_t ow_unprotect(ow_t *const ow, const uint8_t protect)

Unprotect 1-wire from concurrent access.

Note

Used only for OS systems

Return

owOK on success, member of owr_t otherwise

Parameters
  • [inout] ow: 1-Wire handle

  • [in] protect: Set to 1 to protect core, 0 otherwise

owr_t ow_reset_raw(ow_t *const ow)

Reset 1-Wire bus and set connected devices to idle state.

Return

owOK on success, member of owr_t otherwise

Parameters
  • [inout] ow: 1-Wire handle

owr_t ow_reset(ow_t *const ow)

Reset 1-Wire bus and set connected devices to idle state.

Return

owOK on success, member of owr_t otherwise

Note

This function is thread-safe

Parameters
  • [inout] ow: 1-Wire handle

owr_t ow_write_byte_ex_raw(ow_t *const ow, const uint8_t btw, uint8_t *const br)

Write byte over OW and read its response.

Return

owOK on success, member of owr_t otherwise

Parameters
  • [inout] ow: 1-Wire handle

  • [in] btw: Byte to write

  • [out] br: Pointer to read value. Set to NULL if not used

owr_t ow_write_byte_ex(ow_t *const ow, const uint8_t btw, uint8_t *const br)

Write byte over OW and read its response.

Return

owOK on success, member of owr_t otherwise

Note

This function is thread-safe

Parameters
  • [inout] ow: 1-Wire handle

  • [in] btw: Byte to write

  • [out] br: Pointer to read value. Set to NULL if not used

owr_t ow_read_byte_ex_raw(ow_t *const ow, uint8_t *const br)

Read byte from OW device.

Return

owOK on success, member of owr_t otherwise

Parameters
  • [inout] ow: 1-Wire handle

  • [out] br: Pointer to save read value

owr_t ow_read_byte_ex(ow_t *const ow, uint8_t *const br)

Read byte from OW device.

Return

owOK on success, member of owr_t otherwise

Note

This function is thread-safe

Parameters
  • [inout] ow: 1-Wire handle

  • [out] br: Pointer to save read value

owr_t ow_read_bit_ex_raw(ow_t *const ow, uint8_t *const br)

Read sinle bit from OW device.

Return

owOK on success, member of owr_t otherwise

Parameters
  • [inout] ow: 1-Wire handle

  • [out] br: Pointer to save read value, either 1 or 0

owr_t ow_read_bit_ex(ow_t *const ow, uint8_t *const br)

Write byte over OW and read its response.

Return

owOK on success, member of owr_t otherwise

Note

This function is thread-safe

Parameters
  • [inout] ow: 1-Wire handle

  • [in] btw: Byte to write

  • [out] br: Pointer to read value. Set to NULL if not used

owr_t ow_search_reset_raw(ow_t *const ow)

Reset search.

Return

owOK on success, member of owr_t otherwise

Parameters
  • [inout] ow: 1-Wire handle

owr_t ow_search_reset(ow_t *const ow)

Reset search.

Return

owOK on success, member of owr_t otherwise

Note

This function is thread-safe

Parameters
  • [inout] ow: 1-Wire handle

owr_t ow_search_raw(ow_t *const ow, ow_rom_t *const rom_id)

Search for devices on 1-wire bus.

Note

To reset search and to start over, use ow_search_reset function

Return

owOK on success, member of owr_t otherwise

Parameters
  • [inout] ow: 1-Wire handle

  • [out] rom_id: Pointer to ROM structure to save ROM

owr_t ow_search(ow_t *const ow, ow_rom_t *const rom_id)

Search for devices on 1-wire bus.

Note

To reset search and to start over, use ow_search_reset function

Return

owOK on success, member of owr_t otherwise

Note

This function is thread-safe

Parameters
  • [inout] ow: 1-Wire handle

  • [out] rom_id: Pointer to ROM structure to save ROM

owr_t ow_search_with_command_raw(ow_t *const ow, const uint8_t cmd, ow_rom_t *const rom_id)

Search for devices on 1-wire bus with custom search command.

Note

To reset search and to start over, use ow_search_reset function

Return

owOK on success, member of owr_t otherwise

Parameters
  • [inout] ow: 1-Wire handle

  • [in] cmd: command to use for search operation

  • [out] rom_id: Pointer to ROM structure to store address

owr_t ow_search_with_command(ow_t *const ow, const uint8_t cmd, ow_rom_t *const rom_id)

Search for devices on 1-wire bus with custom search command.

Note

To reset search and to start over, use ow_search_reset function

Return

owOK on success, member of owr_t otherwise

Note

This function is thread-safe

Parameters
  • [inout] ow: 1-Wire handle

  • [in] cmd: command to use for search operation

  • [out] rom_id: Pointer to ROM structure to store address

owr_t ow_search_with_command_callback(ow_t *const ow, const uint8_t cmd, size_t *const roms_found, const ow_search_cb_fn func, void *const arg)

Search devices on 1-wire network by using callback function and custom search command.

When new device is detected, callback function func is called to notify user

Return

owOK on success, member of owr_t otherwise

Note

This function is thread-safe

Parameters
  • [in] ow: 1-Wire handle

  • [in] cmd: 1-Wire search command

  • [out] roms_found: Output variable to save number of found devices. Set to NULL if not used

  • [in] func: Callback function to call for each device

  • [in] arg: Custom user argument, used in callback function

owr_t ow_search_with_callback(ow_t *const ow, size_t *const roms_found, const ow_search_cb_fn func, void *const arg)

Search devices on 1-wire network by using callback function and SEARCH_ROM 1-Wire command.

When new device is detected, callback function func is called to notify user

Return

owOK on success, member of owr_t otherwise

Note

This function is thread-safe

Parameters
  • [in] ow: 1-Wire handle

  • [out] roms_found: Output variable to save number of found devices. Set to NULL if not used

  • [in] func: Callback function to call for each device

  • [in] arg: Custom user argument, used in callback function

owr_t ow_search_devices_with_command_raw(ow_t *const ow, const uint8_t cmd, ow_rom_t *const rom_id_arr, const size_t rom_len, size_t *const roms_found)

Search for devices on 1-Wire network with command and store ROM IDs to input array.

Return

owOK on success, member of owr_t otherwise

Parameters
  • [in] ow: 1-Wire handle

  • [in] cmd: 1-Wire search command

  • [in] rom_id_arr: Pointer to output array to store found ROM IDs into

  • [in] rom_len: Length of input ROM array

  • [out] roms_found: Output variable to save number of found devices. Set to NULL if not used

owr_t ow_search_devices_with_command(ow_t *const ow, const uint8_t cmd, ow_rom_t *const rom_id_arr, const size_t rom_len, size_t *const roms_found)

Search for devices on 1-Wire network with command and store ROM IDs to input array.

Return

owOK on success, member of owr_t otherwise

Note

This function is thread-safe

Parameters
  • [in] ow: 1-Wire handle

  • [in] cmd: 1-Wire search command

  • [in] rom_id_arr: Pointer to output array to store found ROM IDs into

  • [in] rom_len: Length of input ROM array

  • [out] roms_found: Output variable to save number of found devices. Set to NULL if not used

owr_t ow_search_devices_raw(ow_t *const ow, ow_rom_t *const rom_id_arr, const size_t rom_len, size_t *const roms_found)

Search for devices on 1-Wire network with default command and store ROM IDs to input array.

Return

owOK on success, member of owr_t otherwise

Parameters
  • [in] ow: 1-Wire handle

  • [in] rom_id_arr: Pointer to output array to store found ROM IDs into

  • [in] rom_len: Length of input ROM array

  • [out] roms_found: Output variable to save number of found devices. Set to NULL if not used

owr_t ow_search_devices(ow_t *const ow, ow_rom_t *const rom_id_arr, const size_t rom_len, size_t *const roms_found)

Search for devices on 1-Wire network with default command and store ROM IDs to input array.

Return

owOK on success, member of owr_t otherwise

Note

This function is thread-safe

Parameters
  • [in] ow: 1-Wire handle

  • [in] rom_id_arr: Pointer to output array to store found ROM IDs into

  • [in] rom_len: Length of input ROM array

  • [out] roms_found: Output variable to save number of found devices. Set to NULL if not used

owr_t ow_match_rom_raw(ow_t *const ow, const ow_rom_t *const rom_id)

Select device on 1-wire network with exact ROM number.

Return

owrOK on success, member of owr_t otherwise

Parameters
  • [in] ow: 1-Wire handle

  • [in] rom_id: 1-Wire device address to match device

owr_t ow_match_rom(ow_t *const ow, const ow_rom_t *const rom_id)

Select device on 1-wire network with exact ROM number.

Return

owrOK on success, member of owr_t otherwise

Note

This function is thread-safe

Parameters
  • [in] ow: 1-Wire handle

  • [in] rom_id: 1-Wire device address to match device

owr_t ow_skip_rom_raw(ow_t *const ow)

Skip ROM address and select all devices on the network.

Return

owrOK on success, member of owr_t otherwise

Parameters
  • [in] ow: 1-Wire handle

owr_t ow_skip_rom(ow_t *const ow)

Skip ROM address and select all devices on the network.

Return

owrOK on success, member of owr_t otherwise

Note

This function is thread-safe

Parameters
  • [in] ow: 1-Wire handle

uint8_t ow_crc(const void *const in, const size_t len)

Calculate CRC-8 of input data.

Return

Calculated CRC

Note

This function is reentrant

Parameters
  • [in] in: Input data

  • [in] len: Number of bytes

uint8_t ow_write_byte_raw(ow_t *const ow, const uint8_t b)

Write byte over 1-wire protocol.

Note

This function is deprecated. Use ow_write_byte_ex_raw instead

Return

Received byte over 1-wire protocol

Parameters
  • [inout] ow: 1-Wire handle

  • [in] b: Byte to write

uint8_t ow_write_byte(ow_t *const ow, const uint8_t b)

Write byte over 1-wire protocol.

Note

This function is deprecated. Use ow_write_byte_ex_raw instead

Return

Received byte over 1-wire protocol

Note

This function is deprecated. Use ow_write_byte_ex instead

Note

This function is thread-safe

Parameters
  • [inout] ow: 1-Wire handle

  • [in] b: Byte to write

uint8_t ow_read_byte_raw(ow_t *const ow)

Read next byte on 1-Wire.

Note

This function is deprecated. Use ow_read_byte_ex_raw instead

Return

Byte read over 1-Wire

Parameters
  • [inout] ow: 1-Wire handle

uint8_t ow_read_byte(ow_t *const ow)

Read next byte on 1-Wire.

Note

This function is deprecated. Use ow_read_byte_ex_raw instead

Return

Byte read over 1-Wire

Note

This function is deprecated. Use ow_read_byte_ex instead

Note

This function is thread-safe

Parameters
  • [inout] ow: 1-Wire handle

uint8_t ow_read_bit_raw(ow_t *const ow)

Read single bit on 1-Wire network.

Note

This function is deprecated. Use ow_read_bit_ex_raw instead

Return

Bit value

Parameters
  • [inout] ow: 1-Wire handle

uint8_t ow_read_bit(ow_t *const ow)

Read single bit on 1-Wire network.

Note

This function is deprecated. Use ow_read_bit_ex_raw instead

Return

Bit value

Note

This function is deprecated. Use ow_read_bit_ex instead

Note

This function is thread-safe

Parameters
  • [inout] ow: 1-Wire handle

struct ow_rom_t
#include <ow.h>

ROM structure.

Public Members

uint8_t rom[8]

8-bytes ROM address

struct ow_t
#include <ow.h>

1-Wire structure

Public Members

ow_rom_t rom

ROM address of last device found. When searching for new devices, we always need last found address, to be able to decide which way to go next time during scan.

uint8_t disrepancy

Disrepancy value on last search

void *arg

User custom argument

const ow_ll_drv_t *ll_drv

Low-level functions driver

OW_CFG_OS_MUTEX_HANDLE mutex

Mutex handle