Skip to content

Commit cdcb56f

Browse files
authored
Merge pull request #15 from fourstix/b_rw_fix
updated write/read
2 parents b4ae633 + cd16991 commit cdcb56f

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

sparkfun_qwiicas3935.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,6 @@ def _read_register(self, register):
590590
raise ValueError("Register value must be in the range of 0x00 to 0x08")
591591

592592
with self._i2c as i2c:
593-
i2c.write(bytes([0x00]))
594593
# Write to the base address, then read all data registers in a
595594
# single block read. Then return the desired value from the list.
596595
# Successive individual byte reads, tend to fail. This trick
@@ -600,7 +599,7 @@ def _read_register(self, register):
600599
# trick is required because smbus doesn't support repeated I2C
601600
# starts to read the registers directly (singularly) on the sensor.
602601
result = bytearray(9)
603-
i2c.readinto(result)
602+
i2c.write_then_readinto(bytes([0x00]), result)
604603
if self._debug:
605604
print([hex(i) for i in result])
606605
print("$%02X => %s" % (register, hex(result[register])))
@@ -612,7 +611,6 @@ def _read_byte(self, register):
612611
# contains the lightning look-up tables and calibration registers.
613612
# The read_register is more efficent for more frequent data registers.
614613
with self._i2c as i2c:
615-
i2c.write(bytes([0x00]))
616614
# Write to the base address, then read all data registers in a
617615
# single block read. Then return the desired value from the list.
618616
# Successive individual byte reads, tend to fail. This trick
@@ -624,7 +622,7 @@ def _read_byte(self, register):
624622
# trick is required because smbus doesn't support repeated I2C
625623
# starts to read the registers directly (singularly) on the sensor.
626624
result = bytearray(0x3E)
627-
i2c.readinto(result)
625+
i2c.write_then_readinto(bytes([0x00]), result)
628626
if self._debug:
629627
print([hex(i) for i in result])
630628
print("$%02X => %s" % (register, hex(result[register])))

0 commit comments

Comments
 (0)