Version: v3.7.1 Latest Latest

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

Go to latest
Published: Apr 27, 2023 License: Apache-2.0 Imports: 8 Imported by: 1



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.




// Make sure periph is initialized.
if _, err := host.Init(); err != nil {

// Use i2creg I²C bus registry to find the first available I²C bus.
b, err := i2creg.Open("")
if err != nil {
defer b.Close()

// Open the DS248x to get a 1-wire bus.
ob, err := ds248x.New(b, 0x18, &ds248x.DefaultOpts)
if err != nil {
// Search devices on the bus
devices, err := ob.Search(false)
if err != nil {
fmt.Printf("Found %d 1-wire devices: ", len(devices))
for _, d := range devices {
	fmt.Printf(" %#16x", uint64(d))




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


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.


This section is empty.


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) ChannelSelect added in v3.6.10

func (d *Dev) ChannelSelect(ch int) error

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) 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) SelectedChannel added in v3.6.10

func (d *Dev) SelectedChannel() int

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.

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Ω.

Source Files

Jump to

Keyboard shortcuts

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