View Source grisp_onewire (grisp v2.8.0)
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.
Summary
Functions
Reset the bus and check the register for devices.
Reset device and activate active pullup (APU).
Read one data byte from the 1-Wire line.
Reset the 1-Wire Master and terminate any ongoing 1-Wire communication.
Search the bus for devices.
Run a 1-Wire transaction.
Write one data byte to the 1-Wire line.
Write configuration into 1-Wire master register.
Functions
-spec 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
Atom | Description |
---|---|
nothing_present | No device on the bus detected |
presence_detected | Some devices on the bus detected |
short_detected | A short circuit between data and ground on the bus detected |
Command code: b4h
.
-spec 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 one data byte from the 1-Wire line.
This function can only be used inside of a transaction/1
call.
Command codes: 96h
, e1h
-spec 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
.
-spec 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]]
-spec transaction(fun()) -> 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
-spec write_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
_
-spec write_config([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
Atom | Integer | Configuration Bit | Activates |
---|---|---|---|
apu | 1 | Bit 0 (APU) | Active pullup |
spu | 4 | Bit 2 (SPU) | Strong pullup |
overdrive | 8 | Bit 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
.