Committer:
atommota
Date:
Thu Oct 27 19:43:20 2011 +0000
Revision:
1:3a46d098c175
Parent:
0:0c0be03e887d
Changed default output data rate to 100Hz (from 1000Hz) to reduce noise issues.

Who changed what in which revision?

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