ds248x

package
v2.0.0+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 25, 2017 License: Apache-2.0 Imports: 8 Imported by: 0

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
// Open the I²C bus to which the DS248x is connected.
i2cBus, err := i2creg.Open("")
if err != nil {
	log.Fatal(err)
}
defer i2cBus.Close()

// Open the DS248x to get a 1-wire bus.
owBus, err := New(i2cBus, nil)
if err != nil {
	log.Fatal(err)
}
// Search devices on the bus
devices, err := owBus.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

View Source
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

func New(i i2c.Bus, opts *Opts) (*Dev, error)

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) Halt

func (d *Dev) Halt() error

Halt implements devices.Device.

func (*Dev) Search

func (d *Dev) Search(alarmOnly bool) ([]onewire.Address, error)

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) String

func (d *Dev) String() string

func (*Dev) Tx

func (d *Dev) Tx(w, r []byte, power onewire.Pullup) error

Tx performs a bus transaction, sending and receiving bytes, and ending by pulling the bus high either weakly or strongly depending on the value of power.

A strong pull-up is typically required to power temperature conversion or EEPROM writes.

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.

type PupOhm

type PupOhm uint8

PupOhm controls the strength of the passive pull-up resistor on the 1-wire data line. The default value is 1000Ω.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL