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