MEMS sensor drivers and tilt-compensated compass using the STEVAL-MKI124V1 header board: LPS331 pressure sensor, LSM303DLHC magnetometer/accelerometer and L3GD20 gyroscope.

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MKI124V1.h Source File

MKI124V1.h

00001 // Defines for the MEMS sensors on the STEVAL-MKI124V1 board
00002 // Liam Goudge. March 2014
00003 
00004 // LPS331AP MEMS pressure and temperature sensor
00005 #define LPS331addr      0xBA // I2C address of the sensor for writes (line SAO is tied high on this board so bit 1=1. Note this may not work on other boards).
00006 
00007 #define pWHO_AM_I        0x0F // "ping" register. Device will respond even when in sleep mode
00008 #define pRES_CONF        0x10 // Reset value is 0x7A (512 pressure samples and 128 temperature samples)
00009 #define pCTRL_REG1       0x20
00010 #define pCTRL_REG2       0x21
00011 #define pCTRL_REG3       0x22
00012 #define pPRESS_OUT_XL    0x28
00013 #define pPRESS_OUT_L     0x29
00014 #define pPRESS_OUT_H     0x2A
00015 #define pTEMP_OUT_L      0x2B // Temperature data. 2's complement. Device will respond when in sleep mode
00016 #define pTEMP_OUT_H      0x2C
00017 
00018 // LSM303DLHC MEMS ascceleratometer, magnetometer and temperature sensor
00019 #define LSM303_m        0x3C // I2C base address of the magnetometer sensor
00020 #define LSM303_a        0x32 // I2C base address of the accelerometer sensor
00021 
00022 // Magnetometer registers
00023 #define mCRA_REG_M       0x00 // Magnetic sensor configuration register A
00024 #define mCRB_REG_M       0x01 // Magnetic sensor configuration register B
00025 #define mMR_REG_M        0x02 // Magnetometer mode register
00026 #define mOUT_X_H_M       0x03 // X-axis magnetic field data High byte
00027 #define mOUT_X_L_M       0x04 // X-axis magnetic field data Low byte
00028 #define mOUT_Z_H_M       0x05 // Z-axis magnetic field data High byte
00029 #define mOUT_Z_L_M       0x06 // Z-axis magnetic field data Low byte
00030 #define mOUT_Y_H_M       0x07 // Y-axis magnetic field data High byte
00031 #define mOUT_Y_L_M       0x08 // Y-axis magnetic field data Low byte
00032 #define mSR_REG_M        0x09 // Magnetometer status register
00033 #define mIRA_REG_M       0x0A // ID register A. Should read 0x48
00034 #define mCTRL_REG1_A     0x20
00035 #define mTEMP_OUT_H_M    0x31 // Magnetometer temperature register High byte
00036 #define mTEMP_OUT_L_M    0x32 // Magnetometer temperature register Low byte
00037 
00038 // Accelerometer registers
00039 #define aCTRL_REG1_A     0x20 // Accelerometer output data rate ODR, low power modes etc
00040 #define aCTRL_REG4_A     0x23 // Accelerometer full scale selection etc
00041 #define aOUT_X_L_A       0x28 // Accelerometer X axis low byte
00042 #define aOUT_X_H_A       0x29 // Accelerometer X axis high byte
00043 #define aOUT_Y_L_A       0x2A // Accelerometer Y axis low byte
00044 #define aOUT_Y_H_A       0x2B // Accelerometer Y axis high byte
00045 #define aOUT_Z_L_A       0x2C // Accelerometer Z axis low byte
00046 #define aOUT_Z_H_A       0x2D // Accelerometer Z axis high byte
00047 
00048 // L3GD20 MEMS gyro. 3 axis angular rate sensor
00049 #define L3GD20_ADDR     0xD6 // I2C base address of the gyro
00050 
00051 #define gWHO_AM_I        0x0F // Ping register. Response is 0xD4. Responds even when device is off
00052 #define gCTRL_REG1       0x20 // Sets Output Data Rate, Bandwidth and Power mode
00053 #define gCTRL_REG4       0x23 // 
00054 #define gOUT_TEMP        0x26 // Temperature data. 8 bit resolution
00055 #define gOUT_X_L         0x28 // X-axis angular rate low byte expressed as 2's complement
00056 #define gOUT_X_H         0x29 // X-axis angular rate high byte
00057 #define gOUT_Y_L         0x2A
00058 #define gOUT_Y_H         0x2B
00059 #define gOUT_Z_L         0x2C
00060 #define gOUT_Z_H         0x2D
00061 
00062 
00063 // Structs
00064 typedef struct{   
00065     float   pitch;
00066     float   roll;
00067     float   Xrotation;
00068     float   Yrotation;
00069     float   Zrotation;
00070     float   heading;
00071     float   tempC;
00072     float   pressuremB;
00073     } SensorState_t;
00074     
00075 
00076 
00077