From 9541d2a8e0ee96d20722142222a2e17df9b9caed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Volker=20Sch=C3=B6nefeld?= Date: Thu, 7 Mar 2024 12:59:03 +0100 Subject: [PATCH] fixed bitmasking issue writing 16 bit integers --- i2c.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/i2c.go b/i2c.go index f1c2d49..a52bdef 100644 --- a/i2c.go +++ b/i2c.go @@ -207,7 +207,7 @@ func (v *I2C) WriteRegU16BE(reg byte, value uint16) error { // value to I2C-device starting from address specified in reg. // SMBus (System Management Bus) protocol over I2C. func (v *I2C) WriteRegU16LE(reg byte, value uint16) error { - w := (value*0xFF00)>>8 + value<<8 + w := (value&0xFF00)>>8 + value<<8 return v.WriteRegU16BE(reg, w) } @@ -228,7 +228,7 @@ func (v *I2C) WriteRegS16BE(reg byte, value int16) error { // value to I2C-device starting from address specified in reg. // SMBus (System Management Bus) protocol over I2C. func (v *I2C) WriteRegS16LE(reg byte, value int16) error { - w := int16((uint16(value)*0xFF00)>>8) + value<<8 + w := int16((uint16(value)&0xFF00)>>8) + value<<8 return v.WriteRegS16BE(reg, w) }