Library to communicate with a ST LIS331DLH

Committer:
atommota
Date:
Sat Nov 13 00:01:57 2010 +0000
Revision:
1:02c1f5bb1c90
Parent:
0:d835d6cac146
Child:
2:d4b810a888b5
fixed some declaration bugs

Who changed what in which revision?

UserRevisionLine numberNew contents of line
atommota 0:d835d6cac146 1 /**
atommota 0:d835d6cac146 2 * @section LICENSE
atommota 0:d835d6cac146 3 *
atommota 0:d835d6cac146 4 *
atommota 0:d835d6cac146 5 * @section DESCRIPTION
atommota 0:d835d6cac146 6 *
atommota 0:d835d6cac146 7 * LIS331 triple axis, digital interface, accelerometer.
atommota 0:d835d6cac146 8 * Based off Aaron Berk's ITG3200 Gyro Library
atommota 0:d835d6cac146 9 *
atommota 0:d835d6cac146 10 * Datasheet:
atommota 0:d835d6cac146 11 *
atommota 0:d835d6cac146 12 * http://www.st.com/stonline/products/literature/ds/13951.pdf
atommota 0:d835d6cac146 13 */
atommota 0:d835d6cac146 14
atommota 0:d835d6cac146 15 #ifndef LIS331_H
atommota 0:d835d6cac146 16 #define LIS331_H
atommota 0:d835d6cac146 17
atommota 0:d835d6cac146 18 /**
atommota 0:d835d6cac146 19 * Includes
atommota 0:d835d6cac146 20 */
atommota 0:d835d6cac146 21 #include "mbed.h"
atommota 0:d835d6cac146 22
atommota 0:d835d6cac146 23 /**
atommota 0:d835d6cac146 24 * Defines
atommota 0:d835d6cac146 25 */
atommota 0:d835d6cac146 26 #define LIS331_I2C_ADDRESS 0x19 //7-bit address.
atommota 0:d835d6cac146 27
atommota 0:d835d6cac146 28 //-----------
atommota 0:d835d6cac146 29 // Registers
atommota 0:d835d6cac146 30 //-----------
atommota 0:d835d6cac146 31 #define WHO_AM_I_REG 0x0F
atommota 0:d835d6cac146 32 #define ACCEL_XOUT_H_REG 0x29
atommota 0:d835d6cac146 33 #define ACCEL_XOUT_L_REG 0x28
atommota 0:d835d6cac146 34 #define ACCEL_YOUT_H_REG 0x2B
atommota 0:d835d6cac146 35 #define ACCEL_YOUT_L_REG 0x2A
atommota 0:d835d6cac146 36 #define ACCEL_ZOUT_H_REG 0x2D
atommota 0:d835d6cac146 37 #define ACCEL_ZOUT_L_REG 0x2C
atommota 0:d835d6cac146 38
atommota 0:d835d6cac146 39
atommota 0:d835d6cac146 40
atommota 0:d835d6cac146 41 #define CTRL_REG_1 0x20
atommota 0:d835d6cac146 42 #define CTRL_REG_2 0x21
atommota 0:d835d6cac146 43 #define CTRL_REG_3 0x22
atommota 0:d835d6cac146 44 #define CTRL_REG_4 0x23
atommota 0:d835d6cac146 45 #define CTRL_REG_5 0x24
atommota 0:d835d6cac146 46
atommota 0:d835d6cac146 47 #define STATUS_REG 0x27
atommota 0:d835d6cac146 48
atommota 0:d835d6cac146 49
atommota 0:d835d6cac146 50 //------------------------------
atommota 0:d835d6cac146 51 // Power Mode and Output Data Rates
atommota 0:d835d6cac146 52 //------------------------------
atommota 0:d835d6cac146 53 #define POWER_DOWN 0x6F
atommota 0:d835d6cac146 54 #define NORMAL_50HZ 0x27
atommota 0:d835d6cac146 55 #define NORMAL_100HZ 0x2F
atommota 0:d835d6cac146 56 #define NORMAL_400HZ 0x37
atommota 0:d835d6cac146 57 #define NORMAL_1000HZ 0x3F
atommota 0:d835d6cac146 58 #define LOW_POWER_0_5HZ 0x47
atommota 0:d835d6cac146 59 #define LOW_POWER_1HZ 0x67
atommota 0:d835d6cac146 60 #define LOW_POWER_2HZ 0x87
atommota 0:d835d6cac146 61 #define LOW_POWER_5HZ 0xA7
atommota 0:d835d6cac146 62 #define LOW_POWER_10HZ 0xC7
atommota 0:d835d6cac146 63
atommota 0:d835d6cac146 64 /**
atommota 0:d835d6cac146 65 * LIS331 triple axis digital accelerometer.
atommota 0:d835d6cac146 66 */
atommota 0:d835d6cac146 67 class LIS331 {
atommota 0:d835d6cac146 68
atommota 0:d835d6cac146 69 public:
atommota 0:d835d6cac146 70
atommota 0:d835d6cac146 71 /**
atommota 0:d835d6cac146 72 * Constructor.
atommota 0:d835d6cac146 73 *
atommota 0:d835d6cac146 74 * Sets FS_SEL to 0x03 for proper opertaion.
atommota 0:d835d6cac146 75 *
atommota 0:d835d6cac146 76 * @param sda - mbed pin to use for the SDA I2C line.
atommota 0:d835d6cac146 77 * @param scl - mbed pin to use for the SCL I2C line.
atommota 0:d835d6cac146 78 */
atommota 0:d835d6cac146 79 LIS331(PinName sda, PinName scl);
atommota 0:d835d6cac146 80
atommota 0:d835d6cac146 81 /**
atommota 0:d835d6cac146 82 * Get the identity of the device.
atommota 0:d835d6cac146 83 *
atommota 0:d835d6cac146 84 * @return The contents of the Who Am I register which contains the I2C
atommota 0:d835d6cac146 85 * address of the device.
atommota 0:d835d6cac146 86 */
atommota 0:d835d6cac146 87 char getWhoAmI(void);
atommota 0:d835d6cac146 88
atommota 0:d835d6cac146 89
atommota 0:d835d6cac146 90
atommota 0:d835d6cac146 91
atommota 1:02c1f5bb1c90 92
atommota 0:d835d6cac146 93
atommota 0:d835d6cac146 94
atommota 0:d835d6cac146 95
atommota 0:d835d6cac146 96
atommota 0:d835d6cac146 97 /**
atommota 0:d835d6cac146 98 * Set the power mode (power down, low power, normal mode)
atommota 0:d835d6cac146 99 *
atommota 0:d835d6cac146 100 *
atommota 0:d835d6cac146 101 * @param
atommota 0:d835d6cac146 102 *
atommota 0:d835d6cac146 103 * Power Mode | Output Data Rate (Hz) | Low-pass Filter Cut off (Hz) | #define
atommota 0:d835d6cac146 104 * --------------------------------------------------------------------------------
atommota 0:d835d6cac146 105 * Power-down | -- | -- | POWER_DOWN
atommota 0:d835d6cac146 106 * Normal | 50 | 37 | NORMAL_50HZ
atommota 0:d835d6cac146 107 * Normal | 100 | 74 | NORMAL_100HZ
atommota 0:d835d6cac146 108 * Normal | 400 | 292 | NORMAL_400HZ
atommota 0:d835d6cac146 109 * Normal | 1000 | 780 | NORMAL_1000HZ
atommota 0:d835d6cac146 110 * Low-power | 0.5 | -- | LOW_POWER_0_5HZ
atommota 0:d835d6cac146 111 * Low-power | 1 | -- | LOW_POWER_1HZ
atommota 0:d835d6cac146 112 * Low-power | 2 | -- | LOW_POWER_2HZ
atommota 0:d835d6cac146 113 * Low-power | 5 | -- | LOW_POWER_5HZ
atommota 0:d835d6cac146 114 * Low-power | 10 | -- | LOW_POWER_10HZ
atommota 0:d835d6cac146 115 */
atommota 0:d835d6cac146 116
atommota 1:02c1f5bb1c90 117 void setPowerMode(char power_mode);
atommota 1:02c1f5bb1c90 118
atommota 1:02c1f5bb1c90 119
atommota 1:02c1f5bb1c90 120
atommota 1:02c1f5bb1c90 121 /**
atommota 1:02c1f5bb1c90 122 * Get the current power mode
atommota 1:02c1f5bb1c90 123 *
atommota 1:02c1f5bb1c90 124 * @return
atommota 1:02c1f5bb1c90 125 */
atommota 1:02c1f5bb1c90 126 char getPowerMode(void);
atommota 0:d835d6cac146 127
atommota 0:d835d6cac146 128
atommota 1:02c1f5bb1c90 129 char getInterruptConfiguration(void);
atommota 0:d835d6cac146 130
atommota 0:d835d6cac146 131 /**
atommota 0:d835d6cac146 132 * Set the interrupt configuration.
atommota 0:d835d6cac146 133 *
atommota 0:d835d6cac146 134 * See datasheet for configuration byte details.
atommota 0:d835d6cac146 135 *
atommota 0:d835d6cac146 136 * 7 6 5 4
atommota 0:d835d6cac146 137 * +-------+-------+------+--------+
atommota 0:d835d6cac146 138 * | IHL | PP_OD | LIR2 | I2_CFG |
atommota 0:d835d6cac146 139 * +-------+-------+------+--------+
atommota 0:d835d6cac146 140 *
atommota 0:d835d6cac146 141 * 3 2 1 0
atommota 0:d835d6cac146 142 * +---------+------+---------+---------+
atommota 0:d835d6cac146 143 * | I2_CFG0 | LIR1 | I1_CFG1 | I1-CFG0 |
atommota 0:d835d6cac146 144 * +---------+------+---------+---------+
atommota 0:d835d6cac146 145 *
atommota 0:d835d6cac146 146 * IHL Interrupt active high or low. 0:active high; 1:active low (default:0)
atommota 0:d835d6cac146 147 * PP_OD Push-pull/Open drain selection on interrupt pad. 0:push-pull; 1:open drain (default:0)
atommota 0:d835d6cac146 148 * LIR2 Latch interupt request on INT2_SRC register, with INT2_SRC register cleared by reading INT2_SRC itself
atommota 0:d835d6cac146 149 * 0: irq not latched; 1:irq latched (default:0)
atommota 0:d835d6cac146 150 * I2_CFG1, I2_CFG0 See datasheet table
atommota 0:d835d6cac146 151 * LIR1 Latch interupt request on INT1_SRC register, with INT1_SRC register cleared by reading INT1_SRC itself
atommota 0:d835d6cac146 152 * 0: irq not latched; 1:irq latched (default:0)
atommota 0:d835d6cac146 153 * I1_CFG1, I1_CFG0 See datasheet table
atommota 0:d835d6cac146 154 *
atommota 0:d835d6cac146 155 * @param config Configuration byte to write to INT_CFG register.
atommota 0:d835d6cac146 156 */
atommota 0:d835d6cac146 157
atommota 0:d835d6cac146 158
atommota 0:d835d6cac146 159 // void setInterruptConfiguration(char config);
atommota 0:d835d6cac146 160
atommota 0:d835d6cac146 161 /**
atommota 0:d835d6cac146 162 * Check the status register
atommota 0:d835d6cac146 163 *
atommota 0:d835d6cac146 164 * @return
atommota 0:d835d6cac146 165 *
atommota 0:d835d6cac146 166 */
atommota 0:d835d6cac146 167
atommota 0:d835d6cac146 168 char getAccelStatus(void);
atommota 0:d835d6cac146 169
atommota 0:d835d6cac146 170
atommota 0:d835d6cac146 171
atommota 0:d835d6cac146 172
atommota 0:d835d6cac146 173 /**
atommota 0:d835d6cac146 174 * Get the temperature of the device.
atommota 0:d835d6cac146 175 *
atommota 0:d835d6cac146 176 * @return The temperature in degrees celsius.
atommota 0:d835d6cac146 177 */
atommota 0:d835d6cac146 178 //float getTemperature(void);
atommota 0:d835d6cac146 179
atommota 0:d835d6cac146 180 /**
atommota 0:d835d6cac146 181 * Get the output for the x-axis gyroscope.
atommota 0:d835d6cac146 182 *
atommota 0:d835d6cac146 183 * Typical sensitivity is 14.375 LSB/(degrees/sec).
atommota 0:d835d6cac146 184 *
atommota 0:d835d6cac146 185 * @return The output on the x-axis in raw ADC counts.
atommota 0:d835d6cac146 186 */
atommota 0:d835d6cac146 187 int getAccelX(void);
atommota 0:d835d6cac146 188
atommota 0:d835d6cac146 189 /**
atommota 0:d835d6cac146 190 * Get the output for the y-axis gyroscope.
atommota 0:d835d6cac146 191 *
atommota 0:d835d6cac146 192 * Typical sensitivity is 14.375 LSB/(degrees/sec).
atommota 0:d835d6cac146 193 *
atommota 0:d835d6cac146 194 * @return The output on the y-axis in raw ADC counts.
atommota 0:d835d6cac146 195 */
atommota 0:d835d6cac146 196 int getAccelY(void);
atommota 0:d835d6cac146 197
atommota 0:d835d6cac146 198 /**
atommota 0:d835d6cac146 199 * Get the output on the z-axis gyroscope.
atommota 0:d835d6cac146 200 *
atommota 0:d835d6cac146 201 * Typical sensitivity is 14.375 LSB/(degrees/sec).
atommota 0:d835d6cac146 202 *
atommota 0:d835d6cac146 203 * @return The output on the z-axis in raw ADC counts.
atommota 0:d835d6cac146 204 */
atommota 0:d835d6cac146 205 int getAccelZ(void);
atommota 0:d835d6cac146 206
atommota 1:02c1f5bb1c90 207
atommota 0:d835d6cac146 208 private:
atommota 0:d835d6cac146 209
atommota 0:d835d6cac146 210 I2C i2c_;
atommota 0:d835d6cac146 211
atommota 0:d835d6cac146 212 };
atommota 0:d835d6cac146 213
atommota 0:d835d6cac146 214 #endif /* LIS331_H */
atommota 0:d835d6cac146 215