Skip to content

Commit 9048051

Browse files
committed
Fixed missing SPI function
1 parent 9561940 commit 9048051

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

sparkfun_qwiicas3935.py

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,8 @@ def __init__(self, i2c, address=DEFAULT_I2C_ADDR, debug=False):
518518
super().__init__(debug)
519519

520520
def _read_register(self, register):
521+
# Read a data register in the 0x00 to 0x08 range.
522+
# Use read_byte function to read registers above this range.
521523
if register < _AFE_GAIN or register > _FREQ_DISP_IRQ:
522524
raise ValueError("Register value must be in the range of 0x00 to 0x08")
523525

@@ -528,9 +530,9 @@ def _read_register(self, register):
528530
# Successive individual byte reads, tend to fail. This trick
529531
# was taken from pcfens/RPi-AS335 python libray on github.
530532
#
531-
# In the original commments, pcfens says this trick is required
532-
# because smbus doesn't support repeated I2C starts to read the
533-
# registers directly on the sensor.
533+
# In the original commments, Phil Fenstermacher (pcfens) says this
534+
# trick is required because smbus doesn't support repeated I2C
535+
# starts to read the registers directly (singularly) on the sensor.
534536
result = bytearray(9)
535537
i2c.readinto(result)
536538
if self._debug:
@@ -540,10 +542,21 @@ def _read_register(self, register):
540542
return result[register]
541543

542544
def _read_byte(self, register):
543-
# read all the registers and get a particular byte value
545+
# Read all the registers and get byte values above 0x08. This range
546+
# contains the lightning look-up tables and calibration regisers.
547+
# The read_register is more efficent for more frequent data registers.
544548
with self._i2c as i2c:
545549
i2c.write(bytes([0x00]),stop=False)
546-
# read all the available bytes available
550+
# Write to the base address, then read all data registers in a
551+
# single block read. Then return the desired value from the list.
552+
# Successive individual byte reads, tend to fail. This trick
553+
# was taken from pcfens/RPi-AS335 python libray on github.
554+
# Note that to get to the calibration registers, we have to read
555+
# 63 bytes (ranging from 0x00 to 0x3D).
556+
#
557+
# In the original commments, Phil Fenstermacher (pcfens) says this
558+
# trick is required because smbus doesn't support repeated I2C
559+
# starts to read the registers directly (singularly) on the sensor.
547560
result = bytearray(0x3E)
548561
i2c.readinto(result)
549562
if self._debug:
@@ -570,6 +583,7 @@ def __init__(self, spi, cs, debug=False):
570583
self._cs.value = True
571584
super().__init__(debug)
572585

586+
573587
def _read_register(self, register):
574588
# set the address read bits
575589
addr = (register | _SPI_READ_MASK) & 0xFF
@@ -578,8 +592,7 @@ def _read_register(self, register):
578592
pass
579593

580594
# configure for SPI mode 1
581-
self._spi.configure(phase=1, polarity=0)
582-
# self._spi.configure(baudrate=2000000, phase=1, polarity=0)
595+
self._spi.configure(baudrate=2000000, phase=1, polarity=0)
583596
# start the read
584597
self._cs.value = False
585598
# write msb first
@@ -599,6 +612,10 @@ def _read_register(self, register):
599612
self._cs.value = True
600613
self._spi.unlock()
601614

615+
def _read_byte(self, register):
616+
# For SPI read_byte function is same as read_register register
617+
return self._read_register(register)
618+
602619
def _write_register(self, register, value):
603620
register &= 0x3F # Write, bit 7, 6 low.
604621

@@ -607,8 +624,7 @@ def _write_register(self, register, value):
607624
pass
608625

609626
# configure for SPI mode 1
610-
# self._spi.configure(baudrate=2000000, phase=1, polarity=0)
611-
self._spi.configure(phase=1, polarity=0)
627+
self._spi.configure(baudrate=2000000, phase=1, polarity=0)
612628
# start the write
613629
self._cs.value = False
614630
# write msb first

0 commit comments

Comments
 (0)