Skip to content

Commit

Permalink
Merge pull request #13 from caternuson/iss11
Browse files Browse the repository at this point in the history
Fixes for SPI class
  • Loading branch information
ladyada committed Oct 10, 2018
2 parents 9e611e2 + 93f24fd commit ddeebd5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
7 changes: 2 additions & 5 deletions adafruit_lsm9ds1.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,8 @@ class LSM9DS1_SPI(LSM9DS1):
"""Driver for the LSM9DS1 connect over SPI."""
# pylint: disable=no-member
def __init__(self, spi, xgcs, mcs):
self._mag_device = spi_device.I2CDevice(spi, mcs)
self._xg_device = spi_device.I2CDevice(spi, xgcs)
self._mag_device = spi_device.SPIDevice(spi, mcs, baudrate=200000, phase=1, polarity=1)
self._xg_device = spi_device.SPIDevice(spi, xgcs, baudrate=200000, phase=1, polarity=1)
super().__init__()

def _read_u8(self, sensor_type, address):
Expand All @@ -416,7 +416,6 @@ def _read_u8(self, sensor_type, address):
else:
device = self._xg_device
with device as spi:
spi.configure(baudrate=200000, phase=0, polarity=0)
self._BUFFER[0] = (address | 0x80) & 0xFF
spi.write(self._BUFFER, end=1)
spi.readinto(self._BUFFER, end=1)
Expand All @@ -428,7 +427,6 @@ def _read_bytes(self, sensor_type, address, count, buf):
else:
device = self._xg_device
with device as spi:
spi.configure(baudrate=200000, phase=0, polarity=0)
buf[0] = (address | 0x80) & 0xFF
spi.write(buf, end=1)
spi.readinto(buf, end=count)
Expand All @@ -439,7 +437,6 @@ def _write_u8(self, sensor_type, address, val):
else:
device = self._xg_device
with device as spi:
spi.configure(baudrate=200000, phase=0, polarity=0)
self._BUFFER[0] = (address & 0x7F) & 0xFF
self._BUFFER[1] = val & 0xFF
spi.write(self._BUFFER, end=2)
11 changes: 11 additions & 0 deletions examples/lsm9ds1_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@
i2c = busio.I2C(board.SCL, board.SDA)
sensor = adafruit_lsm9ds1.LSM9DS1_I2C(i2c)

#SPI connection:
# from digitalio import DigitalInOut, Direction
# spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
# csag = DigitalInOut(board.D5)
# csag.direction = Direction.OUTPUT
# csag.value = True
# csm = DigitalInOut(board.D6)
# csm.direction = Direction.OUTPUT
# csm.value = True
# sensor = adafruit_lsm9ds1.LSM9DS1_SPI(spi, csag, csm)

# Main loop will read the acceleration, magnetometer, gyroscope, Temperature
# values every second and print them out.
while True:
Expand Down

0 comments on commit ddeebd5

Please sign in to comment.