Documentation ¶
Overview ¶
Package ds248x controls a Maxim DS2483 or DS2482-100 1-wire interface chip over I²C.
Datasheets ¶
https://www.maximintegrated.com/en/products/digital/one-wire/DS2483.html
https://www.maximintegrated.com/en/products/interface/controllers-expanders/DS2482-100.html
Example ¶
package main import ( "fmt" "log" "periph.io/x/periph/conn/i2c/i2creg" "periph.io/x/periph/devices/ds248x" "periph.io/x/periph/host" ) func main() { // Make sure periph is initialized. if _, err := host.Init(); err != nil { log.Fatal(err) } // Use i2creg I²C bus registry to find the first available I²C bus. b, err := i2creg.Open("") if err != nil { log.Fatal(err) } defer b.Close() // Open the DS248x to get a 1-wire bus. ob, err := ds248x.New(b, nil) if err != nil { log.Fatal(err) } // Search devices on the bus devices, err := ob.Search(false) if err != nil { log.Fatal(err) } fmt.Printf("Found %d 1-wire devices: ", len(devices)) for _, d := range devices { fmt.Printf(" %#16x", uint64(d)) } fmt.Print("\n") }
Output:
Index ¶
Examples ¶
Constants ¶
const ( // R500Ω passive pull-up resistor. R500Ω = 4 // R1000Ω passive pull-up resistor. R1000Ω = 6 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Dev ¶
type Dev struct { sync.Mutex // lock for the bus while a transaction is in progress // contains filtered or unexported fields }
Dev is a handle to a ds248x device and it implements the onewire.Bus interface.
Dev implements a persistent error model: if a fatal error is encountered it places itself into an error state and immediately returns the last error on all subsequent calls. A fresh Dev, which reinitializes the hardware, must be created to proceed.
A persistent error is only set when there is a problem with the ds248x device itself (or the I²C bus used to access it). Errors on the 1-wire bus do not cause persistent errors and implement the onewire.BusError interface to indicate this fact.
func New ¶
New returns a device object that communicates over I²C to the DS2482/DS2483 controller.
This device object implements onewire.Bus and can be used to access devices on the bus.
func (*Dev) Search ¶
Search performs a "search" cycle on the 1-wire bus and returns the addresses of all devices on the bus if alarmOnly is false and of all devices in alarm state if alarmOnly is true.
If an error occurs during the search the already-discovered devices are returned with the error.
func (*Dev) SearchTriplet ¶
func (d *Dev) SearchTriplet(direction byte) (onewire.TripletResult, error)
SearchTriplet performs a single bit search triplet command on the bus, waits for it to complete and returs the outcome.
SearchTriplet should not be used directly, use Search instead.
type Opts ¶
type Opts struct { Addr uint16 // I²C address, default 0x18 PassivePullup bool // false:use active pull-up, true: disable active pullup // The following options are only available on the ds2483 (not ds2482-100). // The actual value used is the closest possible value (rounded up or down). ResetLow time.Duration // reset low time, range 440μs..740μs PresenceDetect time.Duration // presence detect sample time, range 58μs..76μs Write0Low time.Duration // write zero low time, range 52μs..70μs Write0Recovery time.Duration // write zero recovery time, range 2750ns..25250ns PullupRes PupOhm // passive pull-up resistance, true: 500Ω, false: 1kΩ }
Opts contains options to pass to the constructor.