Skip to content

Fixes for SPI class #11

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 7 commits into from
Nov 29, 2018
Merged
Show file tree
Hide file tree
Changes from 2 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_lsm9ds0.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,8 @@ class LSM9DS0_SPI(LSM9DS0):
"""Driver for the LSM9DS0 connected over SPI."""
# pylint: disable=no-member
def __init__(self, spi, xmcs, gcs):
self._gyro_device = spi_device.I2CDevice(spi, gcs)
self._xm_device = spi_device.I2CDevice(spi, xmcs)
self._mag_device = spi_device.SPIDevice(spi, xmcs, baudrate=200000, phase=1, polarity=1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rest of the code refers to self._gyro_device, is this incorrect or is the rest of the code incorrect?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comment below

self._xg_device = spi_device.SPIDevice(spi, gcs, baudrate=200000, phase=1, polarity=1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rest of the code refers to self._xm_device. Same question as above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comment below

super().__init__()

def _read_u8(self, sensor_type, address):
Expand All @@ -407,7 +407,6 @@ def _read_u8(self, sensor_type, address):
else:
device = self._xm_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 @@ -419,7 +418,6 @@ def _read_bytes(self, sensor_type, address, count, buf):
else:
device = self._xm_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 @@ -430,7 +428,6 @@ def _write_u8(self, sensor_type, address, val):
else:
device = self._xm_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/lsm9ds0_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@
i2c = busio.I2C(board.SCL, board.SDA)
sensor = adafruit_lsm9ds0.LSM9DS0_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_lsm9ds0.LSM9DS0_SPI(spi, csag, csm)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This example copy-pasted from LSM9DS1 is probably all wrong also. For one thing, the CS pins are taken in a different order for the LSM9DS0:

def __init__(self, spi, xmcs, gcs):

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