LSM9DS1 i2c

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
antimo8@alice.it
Date:
Sun Jul 08 11:20:11 2018 +0200
Parent:
2:bf33a982a078
Commit message:
add files

Changed in this revision

LSM9DS1.h Show annotated file Show diff for this revision Revisions of this file
LSM9DS1Reg.h Show annotated file Show diff for this revision Revisions of this file
make.sh Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LSM9DS1.h	Sun Jul 08 11:20:11 2018 +0200
@@ -0,0 +1,82 @@
+/*
+ * LSM9DS1.h
+ *
+ * Created: 05/01/2015 19:49:15
+ *  Author: speirano
+ */
+
+
+#ifndef LSM9DS1_SENSOR_H_
+#define LSM9DS1_SENSOR_H_
+
+//#include <Arduino.h>
+#include <stdbool.h>
+#include <stdint-gcc.h>
+
+
+class LSM9DS1
+{
+
+private:
+    uint8_t _address;
+
+public:
+    LSM9DS1(unsigned int address);
+    ~LSM9DS1() {};
+    virtual bool begin(void)=0;
+
+protected:
+    uint8_t readRegister(uint8_t slaveAddress, uint8_t regToRead);
+    bool writeRegister(uint8_t slaveAddress, uint8_t regToWrite, uint8_t dataToWrite);
+    uint8_t addr(void) {return _address;};
+    int _x, _y, _z;
+    unsigned char _ready_reg;
+    unsigned char _status_reg;
+    bool readInternal(unsigned char high_reg, unsigned char low_reg, int *value);
+};
+
+
+class LSM9DS1_A : public LSM9DS1
+{
+public:
+    LSM9DS1_A(void);
+    bool activate(void);
+    bool deactivate(void);
+    bool begin(void);
+    int readX();
+    int readY();
+    int readZ();
+
+};
+
+class LSM9DS1_G : public LSM9DS1
+{
+public:
+    LSM9DS1_G(void);
+    bool activate(void);
+    bool begin(void);
+    bool deactivate(void);
+    int readX();
+    int readY();
+    int readZ();
+
+};
+class LSM9DS1_M : public LSM9DS1
+{
+public:
+    LSM9DS1_M(void);
+    bool begin(void);
+    bool activate(void);
+    bool deactivate(void);
+    int readX();
+    int readY();
+    int readZ();
+
+};
+
+
+extern  LSM9DS1_A smeAccelerometer;
+extern  LSM9DS1_M smeMagnetic;
+extern  LSM9DS1_G smeGyroscope;
+
+#endif /* LSM9DS1_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LSM9DS1Reg.h	Sun Jul 08 11:20:11 2018 +0200
@@ -0,0 +1,102 @@
+/*
+ * LSM9DS1Reg.h
+ *
+ * Created: 26/04/2015 14:17:29
+ *  Author: speirano
+ */
+
+
+#ifndef LSM9DS1_REG_H_
+#define LSM9DS1_REG_H_
+
+
+
+/* Accelerometer / Gyroscope */
+#define LSM9DS1_AG_ADDRESS     0x6A
+
+#define AG_WHO_AM_I            0x0F
+#define AG_WHO_AM_I_RETURN     0x68
+
+#define AG_CTRL_REG1_G         0x10
+#define AG_ODR_SET             0x20
+
+#define AG_STATUS_REG          0x27
+#define AG_ACCELEROMETER_READY 0x01
+#define AG_GYROSCOPE_READY     0x02
+#define AG_ACC_X_L             0x28
+#define AG_ACC_X_H             0x29
+#define AG_ACC_Y_L             0x2A
+#define AG_ACC_Y_H             0x2B
+#define AG_ACC_Z_L             0x2C
+#define AG_ACC_Z_H             0x2D
+
+#define AG_GYR_X_L             0x18
+#define AG_GYR_X_H             0x19
+#define AG_GYR_Y_L             0x1A
+#define AG_GYR_Y_H             0x1B
+#define AG_GYR_Z_L             0x1C
+#define AG_GYR_Z_H             0x1D
+/* Magnetometer */
+
+#define LSM9DS1_M_ADDRESS      0x1C
+
+#define M_WHO_AM_I            0x0F
+#define M_WHO_AM_I_RETURN     0x3D
+
+#define M_CTRL_REG1_G         0x20
+#define M_ODR_SET             0x20
+#define M_CTRL_REG3_G         0x22
+#define M_OPER_MODE_CONT      0x00
+#define M_OPER_MODE_SINGLE    0x01
+#define M_OPER_MODE_DIS       0x03
+
+#define M_STATUS_REG          0x27
+//#define M_ZYX_X_AXIS_READY    0x01
+//#define M_ZYX_Y_AXIS_READY    0x02
+//#define M_ZYX_Z_AXIS_READY    0x03
+#define M_ZYX_AXIS_READY      0x08
+
+#define M_X_L                 0x28
+#define M_X_H                 0x29
+#define M_Y_L                 0x2A
+#define M_Y_H                 0x2B
+#define M_Z_L                 0x2C
+#define M_Z_H                 0x2D
+
+
+/*Sensors Sensitivity */
+
+/*
+ * Linear acceleration : Reg6_XL  FS[1:0] = 00g +-2, 10+-4g 11+-8g
+ * ranges:
+ * +-2  g       mg/LSB = 0.061
+ * +-4  g       mg/LSB = 0.122
+ * +-8  g       mg/LSB = 0.244
+ */
+#define A_LSB_SENSIT_2MG       0.061
+#define A_LSB_SENSIT_4MG       0.122
+#define A_LSB_SENSIT_8MG       0.244
+
+/*
+ * Angular rate: CTRL_REG1  FS_G[1:0] 00 245, 01 500, 11 2000
+ * +-245    mdps/LSB = 8.75
+ * +-500    mdps/LSB = 17.50
+ * +-2000   mdps/LSB = 70
+ */
+#define G_LSB_SENSIT_245MDPS    8.75
+#define G_LSB_SENSIT_500DPS    17.5
+#define G_LSB_SENSIT_2KMDPS    70
+/*
+ * Magnetic :  REG2_M FS[1:0] 00 +-4 01 +-8 10 +-12 11+-16
+ * +-4       mgauss/LSB = 0.14
+ * +-8       mgauss/LSB = 0.29
+ * +-12      mgauss/LSB = 0.43
+ * +-16      mgauss/LSB = 0.58
+ */
+#define M_LSB_SENSIT_4MG        0.14
+#define M_LSB_SENSIT_8MG        0.29
+#define M_LSB_SENSIT_12MG       0.43
+#define M_LSB_SENSIT_16MG       0.58
+
+
+#endif /* INCFILE1_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/make.sh	Sun Jul 08 11:20:11 2018 +0200
@@ -0,0 +1,2 @@
+mbed compile -c
+cp BUILD/NUCLEO_F302R8/GCC_ARM/Drone_F3.bin /media/kubant/NODE_F302R8/