Skip to content

Commit f4ce26d

Browse files
committed
Added LIS302DL ID check
1 parent db63660 commit f4ce26d

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

stmhal/boards/STM32F4DISC/staccel.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
READWRITE_CMD = const(0x80)
2222
MULTIPLEBYTE_CMD = const(0x40)
2323
LIS302DL_WHO_AM_I_ADDR = const(0x0f)
24+
LIS302DL_WHO_AM_I_VAL = const(0x3b)
2425
LIS302DL_CTRL_REG1_ADDR = const(0x20)
2526
LIS302DL_OUT_X = const(0x29)
2627
# Configuration for 100Hz sampling rate, +-2g range
@@ -38,6 +39,8 @@ def __init__(self):
3839
self.cs_pin.high()
3940
self.spi = SPI(1, SPI.MASTER, baudrate=328125, polarity=0, phase=1, bits=8)
4041
self.wr(LIS302DL_CTRL_REG1_ADDR, bytearray([LIS302DL_CONF]))
42+
if(self.read_id()[0] != LIS302DL_WHO_AM_I_VAL):
43+
raise Exception('LIS302DL accelerometer not present')
4144

4245
def rd(self, addr, nbytes):
4346
if nbytes > 1:

0 commit comments

Comments
 (0)