From 3dfa61987f582fb8c9fb3edfbee99c6e31073bed Mon Sep 17 00:00:00 2001 From: bpds Date: Fri, 29 Dec 2023 16:47:58 +0100 Subject: [PATCH] Fixing inconsistent Read of device id on multiple instantiation. --- adxl345/adxl345.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/adxl345/adxl345.go b/adxl345/adxl345.go index 53dd683..59dac36 100644 --- a/adxl345/adxl345.go +++ b/adxl345/adxl345.go @@ -167,11 +167,13 @@ func (d *Dev) makeDev(o *Opts) error { } } // Verify that the device Id - rx, err := d.Read(DeviceID) + tx := []byte{DeviceID | 0x80, 0x00} + rx := make([]byte, len(tx)) + err = d.c.Tx(tx, rx) if err != nil { return fmt.Errorf("unable to read the deviceID \"%s\"", err.Error()) } - switch byte(rx & 0xff) { + switch rx[1] { case Adxl345: d.name = "adxl345" return nil