Module grisp_onewire

Driver API for the DS2482-100 Single-Channel 1-Wire Master .

Behaviours: gen_server.

Description

Driver API for the DS2482-100 Single-Channel 1-Wire Master .

The functions in this module refer to the function commands documented in the masters data sheet . Each function has a hexadecimal command code that is referenced in the specification sheet.

Function Index

bus_reset/0Reset the bus and check the register for devices.
detect/0Reset device and activate active pullup (APU).
read_byte/0Read one data byte from the 1-Wire line.
reset/0Reset the 1-Wire Master and terminate any ongoing 1-Wire communication.
search/0Search the bus for devices.
transaction/1Run a 1-Wire transaction.
write_byte/1Write one data byte to the 1-Wire line.
write_config/1Write configuration into 1-Wire master register.

Function Details

bus_reset/0

bus_reset() -> nothing_present | presence_detected | short_detected

Reset the bus and check the register for devices.

This function can only be used inside of a transaction/1 call.

Return Value Description

AtomDescription
nothing_presentNo device on the bus detected
presence_detectedSome devices on the bus detected
short_detectedA short circuit between data and ground on the bus detected
Command code: b4h.

detect/0

detect() -> ok

Reset device and activate active pullup (APU).

This function can only be used inside of a transaction/1 call.

See also: reset/0, write_config/1.

read_byte/0

read_byte() -> any()

Read one data byte from the 1-Wire line.

This function can only be used inside of a transaction/1 call.

Command codes: 96h, e1h

reset/0

reset() -> ok

Reset the 1-Wire Master and terminate any ongoing 1-Wire communication.

This function can only be used inside of a transaction/1 call.

Command code: f0h.

search/0

search() -> fail | nothing_present | short_detected | [[byte()]]

Search the bus for devices.

This function can only be used inside of a transaction/1 call.

If there are connected devices, i.e., bus_reset/0 returns presence_detected, this function provides a list of the unique 64-bit addresses of all detected devices. Otherwise, the return values match the values from bus_reset/0 or fail for other failures during the search. The addresses are represented as lists of eight byte values.

Example

With five DS18B20 temperature sensors connected one can list the five device IDs:
  1> grisp_onewire:transaction(fun grisp_onewire:search/0).
  [[40,255,203,173,80,23,4,182],
  [40,255,67,77,96,23,5,138],
  [40,255,190,25,96,23,3,203],
  [40,255,54,42,96,23,5,35],
  [40,255,18,91,96,23,3,62]]

transaction/1

transaction(Fun::function()) -> any()

Run a 1-Wire transaction.

Use this function to make sure that there is only one process running on the 1-Wire.

Example

  2> grisp_onewire:transaction(fun() ->
                                  presence_detected = grisp_onewire:bus_reset(),
                                  grisp_onewire:write_byte(16#cc)
                               end).
  ok

write_byte/1

write_byte(Byte::integer()) -> ok

Write one data byte to the 1-Wire line.

This function can only be used inside of a transaction/1 call.

Command code: a5h

write_config/1

write_config(Conf::[apu | overdrive | spu] | integer()) -> ok

Write configuration into 1-Wire master register.

This function can only be used inside of a transaction/1 call.

The default configuration is 0, i.e., all three configurable bits set to 0. This corresponds to an empty list. Each atom in the list activates the corresponding configuration (sets the bit to 1) and each atom not present in the list leads to a deactivation (sets the bit to 0).

Atom to Integer to Configuration Bit Mapping

AtomIntegerConfiguration Bit Activates
apu1Bit 0 (APU)Active pullup
spu4Bit 2 (SPU)Strong pullup
overdrive8Bit 3 (1WS)1-Wire overdrive speed

Example

To activate active pullup and overdrive speed use:
  3> grisp_onewire:transaction(fun() -> grisp_onewire:write_config([apu, overdrive]) end).
  ok
This is the same as:
  4> grisp_onewire:transaction(fun() -> grisp_onewire:write_config(1 bor 8) end).
  ok
Command code: d2h.


Generated by EDoc