From f4ce26de5c81d6285a26ac172123398bab314e7e Mon Sep 17 00:00:00 2001 From: David Siorpaes Date: Tue, 26 Aug 2014 18:23:00 +0200 Subject: [PATCH 1/2] Added LIS302DL ID check --- stmhal/boards/STM32F4DISC/staccel.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/stmhal/boards/STM32F4DISC/staccel.py b/stmhal/boards/STM32F4DISC/staccel.py index 8395df803d..986c3a85c6 100755 --- a/stmhal/boards/STM32F4DISC/staccel.py +++ b/stmhal/boards/STM32F4DISC/staccel.py @@ -21,6 +21,7 @@ from pyb import SPI READWRITE_CMD = const(0x80) MULTIPLEBYTE_CMD = const(0x40) LIS302DL_WHO_AM_I_ADDR = const(0x0f) +LIS302DL_WHO_AM_I_VAL = const(0x3b) LIS302DL_CTRL_REG1_ADDR = const(0x20) LIS302DL_OUT_X = const(0x29) # Configuration for 100Hz sampling rate, +-2g range @@ -38,6 +39,8 @@ class STAccel: self.cs_pin.high() self.spi = SPI(1, SPI.MASTER, baudrate=328125, polarity=0, phase=1, bits=8) self.wr(LIS302DL_CTRL_REG1_ADDR, bytearray([LIS302DL_CONF])) + if(self.read_id()[0] != LIS302DL_WHO_AM_I_VAL): + raise Exception('LIS302DL accelerometer not present') def rd(self, addr, nbytes): if nbytes > 1: From e00fb08f99f85deb5632d075b50cc7242740dd1d Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 26 Aug 2014 17:30:48 +0100 Subject: [PATCH 2/2] stmhal, staccel.py: Style cleanup. --- stmhal/boards/STM32F4DISC/staccel.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stmhal/boards/STM32F4DISC/staccel.py b/stmhal/boards/STM32F4DISC/staccel.py index 986c3a85c6..ce2646406a 100755 --- a/stmhal/boards/STM32F4DISC/staccel.py +++ b/stmhal/boards/STM32F4DISC/staccel.py @@ -39,7 +39,7 @@ class STAccel: self.cs_pin.high() self.spi = SPI(1, SPI.MASTER, baudrate=328125, polarity=0, phase=1, bits=8) self.wr(LIS302DL_CTRL_REG1_ADDR, bytearray([LIS302DL_CONF])) - if(self.read_id()[0] != LIS302DL_WHO_AM_I_VAL): + if self.read_id()[0] != LIS302DL_WHO_AM_I_VAL: raise Exception('LIS302DL accelerometer not present') def rd(self, addr, nbytes):