Skip to content

Commit ddeebd5

Browse files
authored
Merge pull request #13 from caternuson/iss11
Fixes for SPI class
2 parents 9e611e2 + 93f24fd commit ddeebd5

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

adafruit_lsm9ds1.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,8 @@ class LSM9DS1_SPI(LSM9DS1):
406406
"""Driver for the LSM9DS1 connect over SPI."""
407407
# pylint: disable=no-member
408408
def __init__(self, spi, xgcs, mcs):
409-
self._mag_device = spi_device.I2CDevice(spi, mcs)
410-
self._xg_device = spi_device.I2CDevice(spi, xgcs)
409+
self._mag_device = spi_device.SPIDevice(spi, mcs, baudrate=200000, phase=1, polarity=1)
410+
self._xg_device = spi_device.SPIDevice(spi, xgcs, baudrate=200000, phase=1, polarity=1)
411411
super().__init__()
412412

413413
def _read_u8(self, sensor_type, address):
@@ -416,7 +416,6 @@ def _read_u8(self, sensor_type, address):
416416
else:
417417
device = self._xg_device
418418
with device as spi:
419-
spi.configure(baudrate=200000, phase=0, polarity=0)
420419
self._BUFFER[0] = (address | 0x80) & 0xFF
421420
spi.write(self._BUFFER, end=1)
422421
spi.readinto(self._BUFFER, end=1)
@@ -428,7 +427,6 @@ def _read_bytes(self, sensor_type, address, count, buf):
428427
else:
429428
device = self._xg_device
430429
with device as spi:
431-
spi.configure(baudrate=200000, phase=0, polarity=0)
432430
buf[0] = (address | 0x80) & 0xFF
433431
spi.write(buf, end=1)
434432
spi.readinto(buf, end=count)
@@ -439,7 +437,6 @@ def _write_u8(self, sensor_type, address, val):
439437
else:
440438
device = self._xg_device
441439
with device as spi:
442-
spi.configure(baudrate=200000, phase=0, polarity=0)
443440
self._BUFFER[0] = (address & 0x7F) & 0xFF
444441
self._BUFFER[1] = val & 0xFF
445442
spi.write(self._BUFFER, end=2)

examples/lsm9ds1_simpletest.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@
99
i2c = busio.I2C(board.SCL, board.SDA)
1010
sensor = adafruit_lsm9ds1.LSM9DS1_I2C(i2c)
1111

12+
#SPI connection:
13+
# from digitalio import DigitalInOut, Direction
14+
# spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
15+
# csag = DigitalInOut(board.D5)
16+
# csag.direction = Direction.OUTPUT
17+
# csag.value = True
18+
# csm = DigitalInOut(board.D6)
19+
# csm.direction = Direction.OUTPUT
20+
# csm.value = True
21+
# sensor = adafruit_lsm9ds1.LSM9DS1_SPI(spi, csag, csm)
22+
1223
# Main loop will read the acceleration, magnetometer, gyroscope, Temperature
1324
# values every second and print them out.
1425
while True:

0 commit comments

Comments
 (0)