From 35a146d60ecae9a8d9482aece8ddce86e8b65cf6 Mon Sep 17 00:00:00 2001 From: deadprogram Date: Fri, 21 Aug 2020 10:12:16 +0200 Subject: [PATCH] lis2mdl: turn on read mode on every read, to ensure that magnetometer data is updated Signed-off-by: deadprogram --- lis2mdl/lis2mdl.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lis2mdl/lis2mdl.go b/lis2mdl/lis2mdl.go index 2686ca6..04cb822 100644 --- a/lis2mdl/lis2mdl.go +++ b/lis2mdl/lis2mdl.go @@ -90,6 +90,12 @@ func (d *Device) Configure(cfg Configuration) { // ReadMagneticField reads the current magnetic field from the device and returns // it in mG (milligauss). 1 mG = 0.1 µT (microtesla). func (d *Device) ReadMagneticField() (x int32, y int32, z int32) { + // turn back on read mode, even though it is supposed to be continuous? + cmd := []byte{0} + cmd[0] = byte(0x80 | d.PowerMode<<4 | d.DataRate<<2 | d.SystemMode) + d.bus.WriteRegister(uint8(d.Address), MAG_MR_CFG_REG_A, cmd) + time.Sleep(10 * time.Millisecond) + data := make([]byte, 6) d.bus.ReadRegister(uint8(d.Address), MAG_OUT_X_L_M, data)