Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
ITG3200.h
00001 /** 00002 * @author Aaron Berk 00003 * 00004 * @section LICENSE 00005 * 00006 * Copyright (c) 2010 ARM Limited 00007 * 00008 * Permission is hereby granted, free of charge, to any person obtaining a copy 00009 * of this software and associated documentation files (the "Software"), to deal 00010 * in the Software without restriction, including without limitation the rights 00011 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00012 * copies of the Software, and to permit persons to whom the Software is 00013 * furnished to do so, subject to the following conditions: 00014 * 00015 * The above copyright notice and this permission notice shall be included in 00016 * all copies or substantial portions of the Software. 00017 * 00018 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00019 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00020 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00021 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00022 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00023 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00024 * THE SOFTWARE. 00025 * 00026 * @section DESCRIPTION 00027 * 00028 * ITG-3200 triple axis, digital interface, gyroscope. 00029 * 00030 * Datasheet: 00031 * 00032 * http://invensense.com/mems/gyro/documents/PS-ITG-3200-00-01.4.pdf 00033 */ 00034 00035 #ifndef ITG3200_H 00036 #define ITG3200_H 00037 00038 /** 00039 * Includes 00040 */ 00041 #include "mbed.h" 00042 00043 /** 00044 * Defines 00045 */ 00046 #define ITG3200_I2C_ADDRESS 0x68 //7-bit address. 00047 00048 //----------- 00049 // Registers 00050 //----------- 00051 #define WHO_AM_I_REG 0x00 00052 #define SMPLRT_DIV_REG 0x15 00053 #define DLPF_FS_REG 0x16 00054 #define INT_CFG_REG 0x17 00055 #define INT_STATUS 0x1A 00056 #define TEMP_OUT_H_REG 0x1B 00057 #define TEMP_OUT_L_REG 0x1C 00058 #define GYRO_XOUT_H_REG 0x1D 00059 #define GYRO_XOUT_L_REG 0x1E 00060 #define GYRO_YOUT_H_REG 0x1F 00061 #define GYRO_YOUT_L_REG 0x20 00062 #define GYRO_ZOUT_H_REG 0x21 00063 #define GYRO_ZOUT_L_REG 0x22 00064 #define PWR_MGM_REG 0x3E 00065 00066 //---------------------------- 00067 // Low Pass Filter Bandwidths 00068 //---------------------------- 00069 #define LPFBW_256HZ 0x00 00070 #define LPFBW_188HZ 0x01 00071 #define LPFBW_98HZ 0x02 00072 #define LPFBW_42HZ 0x03 00073 #define LPFBW_20HZ 0x04 00074 #define LPFBW_10HZ 0x05 00075 #define LPFBW_5HZ 0x06 00076 00077 /** 00078 * ITG-3200 triple axis digital gyroscope. 00079 */ 00080 class ITG3200 { 00081 00082 public: 00083 00084 /** 00085 * Constructor. 00086 * 00087 * Sets FS_SEL to 0x03 for proper opertaion. 00088 * 00089 * @param sda - mbed pin to use for the SDA I2C line. 00090 * @param scl - mbed pin to use for the SCL I2C line. 00091 */ 00092 ITG3200(PinName sda, PinName scl); 00093 00094 /** 00095 * Get the identity of the device. 00096 * 00097 * @return The contents of the Who Am I register which contains the I2C 00098 * address of the device. 00099 */ 00100 char getWhoAmI(void); 00101 00102 /** 00103 * Set the address of the device. 00104 * 00105 * @param address The I2C slave address to write to the Who Am I register 00106 * on the device. 00107 */ 00108 void setWhoAmI(char address); 00109 00110 /** 00111 * Get the sample rate divider. 00112 * 00113 * @return The sample rate divider as a number from 0-255. 00114 */ 00115 char getSampleRateDivider(void); 00116 00117 /** 00118 * Set the sample rate divider. 00119 * 00120 * Fsample = Finternal / (divider + 1), where Finternal = 1kHz or 8kHz, 00121 * as decidied by the DLPF_FS register. 00122 * 00123 * @param The sample rate divider as a number from 0-255. 00124 */ 00125 void setSampleRateDivider(char divider); 00126 00127 /** 00128 * Get the internal sample rate. 00129 * 00130 * @return The internal sample rate in kHz - either 1 or 8. 00131 */ 00132 int getInternalSampleRate(void); 00133 00134 /** 00135 * Set the low pass filter bandwidth. 00136 * 00137 * Also used to set the internal sample rate. 00138 * Pass the #define bandwidth codes as a parameter. 00139 * 00140 * 256Hz -> 8kHz internal sample rate. 00141 * Everything else -> 1kHz internal rate. 00142 * 00143 * @param bandwidth Low pass filter bandwidth code 00144 */ 00145 void setLpBandwidth(char bandwidth); 00146 00147 /** 00148 * Get the interrupt configuration. 00149 * 00150 * See datasheet for register contents details. 00151 * 00152 * 7 6 5 4 00153 * +------+------+--------------+------------------+ 00154 * | ACTL | OPEN | LATCH_INT_EN | INT_ANYRD_2CLEAR | 00155 * +------+------+--------------+------------------+ 00156 * 00157 * 3 2 1 0 00158 * +---+------------+------------+---+ 00159 * | 0 | ITG_RDY_EN | RAW_RDY_EN | 0 | 00160 * +---+------------+------------+---+ 00161 * 00162 * ACTL Logic level for INT output pin; 1 = active low, 0 = active high. 00163 * OPEN Drive type for INT output pin; 1 = open drain, 0 = push-pull. 00164 * LATCH_INT_EN Latch mode; 1 = latch until interrupt is cleared, 00165 * 0 = 50us pulse. 00166 * INT_ANYRD_2CLEAR Latch clear method; 1 = any register read, 00167 * 0 = status register read only. 00168 * ITG_RDY_EN Enable interrupt when device is ready, 00169 * (PLL ready after changing clock source). 00170 * RAW_RDY_EN Enable interrupt when data is available. 00171 * 0 Bits 1 and 3 of the INT_CFG register should be zero. 00172 * 00173 * @return the contents of the INT_CFG register. 00174 */ 00175 char getInterruptConfiguration(void); 00176 00177 /** 00178 * Set the interrupt configuration. 00179 * 00180 * See datasheet for configuration byte details. 00181 * 00182 * 7 6 5 4 00183 * +------+------+--------------+------------------+ 00184 * | ACTL | OPEN | LATCH_INT_EN | INT_ANYRD_2CLEAR | 00185 * +------+------+--------------+------------------+ 00186 * 00187 * 3 2 1 0 00188 * +---+------------+------------+---+ 00189 * | 0 | ITG_RDY_EN | RAW_RDY_EN | 0 | 00190 * +---+------------+------------+---+ 00191 * 00192 * ACTL Logic level for INT output pin; 1 = active low, 0 = active high. 00193 * OPEN Drive type for INT output pin; 1 = open drain, 0 = push-pull. 00194 * LATCH_INT_EN Latch mode; 1 = latch until interrupt is cleared, 00195 * 0 = 50us pulse. 00196 * INT_ANYRD_2CLEAR Latch clear method; 1 = any register read, 00197 * 0 = status register read only. 00198 * ITG_RDY_EN Enable interrupt when device is ready, 00199 * (PLL ready after changing clock source). 00200 * RAW_RDY_EN Enable interrupt when data is available. 00201 * 0 Bits 1 and 3 of the INT_CFG register should be zero. 00202 * 00203 * @param config Configuration byte to write to INT_CFG register. 00204 */ 00205 void setInterruptConfiguration(char config); 00206 00207 /** 00208 * Check the ITG_RDY bit of the INT_STATUS register. 00209 * 00210 * @return True if the ITG_RDY bit is set, corresponding to PLL ready, 00211 * false if the ITG_RDY bit is not set, corresponding to PLL not 00212 * ready. 00213 */ 00214 bool isPllReady(void); 00215 00216 /** 00217 * Check the RAW_DATA_RDY bit of the INT_STATUS register. 00218 * 00219 * @return True if the RAW_DATA_RDY bit is set, corresponding to new data 00220 * in the sensor registers, false if the RAW_DATA_RDY bit is not 00221 * set, corresponding to no new data yet in the sensor registers. 00222 */ 00223 bool isRawDataReady(void); 00224 00225 /** 00226 * Get the temperature of the device. 00227 * 00228 * @return The temperature in degrees celsius. 00229 */ 00230 float getTemperature(void); 00231 00232 /** 00233 * Get the output for the x-axis gyroscope. 00234 * 00235 * Typical sensitivity is 14.375 LSB/(degrees/sec). 00236 * 00237 * @return The output on the x-axis in raw ADC counts. 00238 */ 00239 int getGyroX(void); 00240 00241 /** 00242 * Get the output for the y-axis gyroscope. 00243 * 00244 * Typical sensitivity is 14.375 LSB/(degrees/sec). 00245 * 00246 * @return The output on the y-axis in raw ADC counts. 00247 */ 00248 int getGyroY(void); 00249 00250 /** 00251 * Get the output on the z-axis gyroscope. 00252 * 00253 * Typical sensitivity is 14.375 LSB/(degrees/sec). 00254 * 00255 * @return The output on the z-axis in raw ADC counts. 00256 */ 00257 int getGyroZ(void); 00258 00259 /** 00260 * Get the power management configuration. 00261 * 00262 * See the datasheet for register contents details. 00263 * 00264 * 7 6 5 4 00265 * +---------+-------+---------+---------+ 00266 * | H_RESET | SLEEP | STBY_XG | STBY_YG | 00267 * +---------+-------+---------+---------+ 00268 * 00269 * 3 2 1 0 00270 * +---------+----------+----------+----------+ 00271 * | STBY_ZG | CLK_SEL2 | CLK_SEL1 | CLK_SEL0 | 00272 * +---------+----------+----------+----------+ 00273 * 00274 * H_RESET Reset device and internal registers to the power-up-default settings. 00275 * SLEEP Enable low power sleep mode. 00276 * STBY_XG Put gyro X in standby mode (1=standby, 0=normal). 00277 * STBY_YG Put gyro Y in standby mode (1=standby, 0=normal). 00278 * STBY_ZG Put gyro Z in standby mode (1=standby, 0=normal). 00279 * CLK_SEL Select device clock source: 00280 * 00281 * CLK_SEL | Clock Source 00282 * --------+-------------- 00283 * 0 Internal oscillator 00284 * 1 PLL with X Gyro reference 00285 * 2 PLL with Y Gyro reference 00286 * 3 PLL with Z Gyro reference 00287 * 4 PLL with external 32.768kHz reference 00288 * 5 PLL with external 19.2MHz reference 00289 * 6 Reserved 00290 * 7 Reserved 00291 * 00292 * @return The contents of the PWR_MGM register. 00293 */ 00294 char getPowerManagement(void); 00295 00296 /** 00297 * Set power management configuration. 00298 * 00299 * See the datasheet for configuration byte details 00300 * 00301 * 7 6 5 4 00302 * +---------+-------+---------+---------+ 00303 * | H_RESET | SLEEP | STBY_XG | STBY_YG | 00304 * +---------+-------+---------+---------+ 00305 * 00306 * 3 2 1 0 00307 * +---------+----------+----------+----------+ 00308 * | STBY_ZG | CLK_SEL2 | CLK_SEL1 | CLK_SEL0 | 00309 * +---------+----------+----------+----------+ 00310 * 00311 * H_RESET Reset device and internal registers to the power-up-default settings. 00312 * SLEEP Enable low power sleep mode. 00313 * STBY_XG Put gyro X in standby mode (1=standby, 0=normal). 00314 * STBY_YG Put gyro Y in standby mode (1=standby, 0=normal). 00315 * STBY_ZG Put gyro Z in standby mode (1=standby, 0=normal). 00316 * CLK_SEL Select device clock source: 00317 * 00318 * CLK_SEL | Clock Source 00319 * --------+-------------- 00320 * 0 Internal oscillator 00321 * 1 PLL with X Gyro reference 00322 * 2 PLL with Y Gyro reference 00323 * 3 PLL with Z Gyro reference 00324 * 4 PLL with external 32.768kHz reference 00325 * 5 PLL with external 19.2MHz reference 00326 * 6 Reserved 00327 * 7 Reserved 00328 * 00329 * @param config The configuration byte to write to the PWR_MGM register. 00330 */ 00331 void setPowerManagement(char config); 00332 00333 private: 00334 00335 I2C i2c_; 00336 00337 }; 00338 00339 #endif /* ITG3200_H */
Generated on Tue Jul 19 2022 10:36:41 by
1.7.2