ds248x

package
v3.4.991+incompatible Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2019 License: Apache-2.0 Imports: 7 Imported by: 0

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
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, 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

Examples

Constants

View Source
const (
	// R500Ω passive pull-up resistor.
	R500Ω = 4
	// R1000Ω passive pull-up resistor.
	R1000Ω = 6
)

Variables

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

func New(i i2c.Bus, addr uint16, 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.

Valid I²C addresses are 0x18, 0x19, 0x20 and 0x21.

func (*Dev) Halt

func (d *Dev) Halt() error

Halt implements conn.Resource.

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 {
	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