Skip to content

Fixes for SPI class #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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