Documentation ¶
Overview ¶
Package ds248x controls a Maxim DS2483 or DS2482-100 1-wire interface chip over I²C.
More details ¶
See https://periph.io/device/ds248x/ for more details about the device.
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 ¶
// 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, 0x18, &ds248x.DefaultOpts) 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 ¶
- Constants
- Variables
- type Dev
- func (d *Dev) ChannelSelect(ch int) error
- func (d *Dev) Halt() error
- func (d *Dev) Search(alarmOnly bool) ([]onewire.Address, error)
- func (d *Dev) SearchTriplet(direction byte) (onewire.TripletResult, error)
- func (d *Dev) SelectedChannel() int
- func (d *Dev) String() string
- func (d *Dev) Tx(w, r []byte, power onewire.Pullup) error
- type Opts
- type PupOhm
Examples ¶
Constants ¶
const ( // R500Ω passive pull-up resistor. R500Ω = 4 // R1000Ω passive pull-up resistor. R1000Ω = 6 )
Variables ¶
var DefaultOpts = Opts{ PassivePullup: false, ResetLow: 560 * time.Microsecond, PresenceDetect: 68 * time.Microsecond, Write0Low: 64 * time.Microsecond, Write0Recovery: 5250 * time.Nanosecond, PullupRes: R1000Ω, }
DefaultOpts is the recommended default options.
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.
Valid I²C addresses are 0x18, 0x19, 0x20 and 0x21.
func (*Dev) ChannelSelect ¶ added in v3.6.10
ChannelSelect function is for selecting one of eight 1-w channels on DS2482-800. On other chips it does nothing. Channel selection values are between 0 and 7. It is expected that application keeps track of with 1-w device is connected to with channel. Communication error is returned if present.
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.
func (*Dev) SelectedChannel ¶ added in v3.6.10
SelectedChannel function is to read with 1-w channel selected on DS2482-800. On other chips it always returns 0. It is expected that application keeps track of with 1-w device is connected to with channel. On error returns -1.
type Opts ¶
type Opts struct { 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.