I2Cdevlib

I2C device library collection for AVR/Arduino or other C++-based MCUs

ITG3200/ITG3200.h
00001 // I2Cdev library collection - ITG3200 I2C device class header file
00002 // Based on InvenSense ITG-3200 datasheet rev. 1.4, 3/30/2010 (PS-ITG-3200A-00-01.4)
00003 // 7/31/2011 by Jeff Rowberg <jeff@rowberg.net>
00004 // Updates should (hopefully) always be available at https://github.com/jrowberg/i2cdevlib
00005 //
00006 // Changelog:
00007 //     2011-07-31 - initial release
00008 
00009 /* ============================================
00010 I2Cdev device library code is placed under the MIT license
00011 Copyright (c) 2011 Jeff Rowberg
00012 
00013 Permission is hereby granted, free of charge, to any person obtaining a copy
00014 of this software and associated documentation files (the "Software"), to deal
00015 in the Software without restriction, including without limitation the rights
00016 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00017 copies of the Software, and to permit persons to whom the Software is
00018 furnished to do so, subject to the following conditions:
00019 
00020 The above copyright notice and this permission notice shall be included in
00021 all copies or substantial portions of the Software.
00022 
00023 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00024 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00025 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00026 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00027 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00028 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00029 THE SOFTWARE.
00030 ===============================================
00031 */
00032 
00033 #ifndef _ITG3200_H_
00034 #define _ITG3200_H_
00035 
00036 #include "I2Cdev.h"
00037 
00038 #define ITG3200_ADDRESS_AD0_LOW     0x68 // address pin low (GND), default for SparkFun IMU Digital Combo board
00039 #define ITG3200_ADDRESS_AD0_HIGH    0x69 // address pin high (VCC), default for SparkFun ITG-3200 Breakout board
00040 #define ITG3200_DEFAULT_ADDRESS     ITG3200_ADDRESS_AD0_LOW
00041 
00042 #define ITG3200_RA_WHO_AM_I         0x00
00043 #define ITG3200_RA_SMPLRT_DIV       0x15
00044 #define ITG3200_RA_DLPF_FS          0x16
00045 #define ITG3200_RA_INT_CFG          0x17
00046 #define ITG3200_RA_INT_STATUS       0x1A
00047 #define ITG3200_RA_TEMP_OUT_H       0x1B
00048 #define ITG3200_RA_TEMP_OUT_L       0x1C
00049 #define ITG3200_RA_GYRO_XOUT_H      0x1D
00050 #define ITG3200_RA_GYRO_XOUT_L      0x1E
00051 #define ITG3200_RA_GYRO_YOUT_H      0x1F
00052 #define ITG3200_RA_GYRO_YOUT_L      0x20
00053 #define ITG3200_RA_GYRO_ZOUT_H      0x21
00054 #define ITG3200_RA_GYRO_ZOUT_L      0x22
00055 #define ITG3200_RA_PWR_MGM          0x3E
00056 
00057 #define ITG3200_DEVID_BIT           6
00058 #define ITG3200_DEVID_LENGTH        6
00059 
00060 #define ITG3200_DF_FS_SEL_BIT       4
00061 #define ITG3200_DF_FS_SEL_LENGTH    2
00062 #define ITG3200_DF_DLPF_CFG_BIT     2
00063 #define ITG3200_DF_DLPF_CFG_LENGTH  3
00064 
00065 #define ITG3200_FULLSCALE_2000      0x03
00066 
00067 #define ITG3200_DLPF_BW_256         0x00
00068 #define ITG3200_DLPF_BW_188         0x01
00069 #define ITG3200_DLPF_BW_98          0x02
00070 #define ITG3200_DLPF_BW_42          0x03
00071 #define ITG3200_DLPF_BW_20          0x04
00072 #define ITG3200_DLPF_BW_10          0x05
00073 #define ITG3200_DLPF_BW_5           0x06
00074 
00075 #define ITG3200_INTCFG_ACTL_BIT             7
00076 #define ITG3200_INTCFG_OPEN_BIT             6
00077 #define ITG3200_INTCFG_LATCH_INT_EN_BIT     5
00078 #define ITG3200_INTCFG_INT_ANYRD_2CLEAR_BIT 4
00079 #define ITG3200_INTCFG_ITG_RDY_EN_BIT       2
00080 #define ITG3200_INTCFG_RAW_RDY_EN_BIT       0
00081 
00082 #define ITG3200_INTMODE_ACTIVEHIGH  0x00
00083 #define ITG3200_INTMODE_ACTIVELOW   0x01
00084 
00085 #define ITG3200_INTDRV_PUSHPULL     0x00
00086 #define ITG3200_INTDRV_OPENDRAIN    0x01
00087 
00088 #define ITG3200_INTLATCH_50USPULSE  0x00
00089 #define ITG3200_INTLATCH_WAITCLEAR  0x01
00090 
00091 #define ITG3200_INTCLEAR_STATUSREAD 0x00
00092 #define ITG3200_INTCLEAR_ANYREAD    0x01
00093 
00094 #define ITG3200_INTSTAT_ITG_RDY_BIT         2
00095 #define ITG3200_INTSTAT_RAW_DATA_READY_BIT  0
00096 
00097 #define ITG3200_PWR_H_RESET_BIT     7
00098 #define ITG3200_PWR_SLEEP_BIT       6
00099 #define ITG3200_PWR_STBY_XG_BIT     5
00100 #define ITG3200_PWR_STBY_YG_BIT     4
00101 #define ITG3200_PWR_STBY_ZG_BIT     3
00102 #define ITG3200_PWR_CLK_SEL_BIT     2
00103 #define ITG3200_PWR_CLK_SEL_LENGTH  3
00104 
00105 #define ITG3200_CLOCK_INTERNAL      0x00
00106 #define ITG3200_CLOCK_PLL_XGYRO     0x01
00107 #define ITG3200_CLOCK_PLL_YGYRO     0x02
00108 #define ITG3200_CLOCK_PLL_ZGYRO     0x03
00109 #define ITG3200_CLOCK_PLL_EXT32K    0x04
00110 #define ITG3200_CLOCK_PLL_EXT19M    0x05
00111 
00112 class ITG3200 {
00113     public:
00114         ITG3200();
00115         ITG3200(uint8_t address);
00116         
00117         void initialize();
00118         bool testConnection();
00119         
00120         // WHO_AM_I register
00121         uint8_t getDeviceID();
00122         void setDeviceID(uint8_t id);
00123 
00124         // SMPLRT_DIV register
00125         uint8_t getRate();
00126         void setRate(uint8_t rate);
00127 
00128         // DLPF_FS register
00129         uint8_t getFullScaleRange();
00130         void setFullScaleRange(uint8_t range);
00131         uint8_t getDLPFBandwidth();
00132         void setDLPFBandwidth(uint8_t bandwidth);
00133         
00134         // INT_CFG register
00135         bool getInterruptMode();
00136         void setInterruptMode(bool mode);
00137         bool getInterruptDrive();
00138         void setInterruptDrive(bool drive);
00139         bool getInterruptLatch();
00140         void setInterruptLatch(bool latch);
00141         bool getInterruptLatchClear();
00142         void setInterruptLatchClear(bool clear);
00143         bool getIntDeviceReadyEnabled();
00144         void setIntDeviceReadyEnabled(bool enabled);
00145         bool getIntDataReadyEnabled();
00146         void setIntDataReadyEnabled(bool enabled);
00147 
00148         // INT_STATUS register
00149         bool getIntDeviceReadyStatus();
00150         bool getIntDataReadyStatus();
00151         
00152         // TEMP_OUT_* registers
00153         int16_t getTemperature();
00154         
00155         // GYRO_*OUT_* registers
00156         void getRotation(int16_t* x, int16_t* y, int16_t* z);
00157         int16_t getRotationX();
00158         int16_t getRotationY();
00159         int16_t getRotationZ();
00160 
00161         // PWR_MGM register
00162         void reset();
00163         bool getSleepEnabled();
00164         void setSleepEnabled(bool enabled);
00165         bool getStandbyXEnabled();
00166         void setStandbyXEnabled(bool enabled);
00167         bool getStandbyYEnabled();
00168         void setStandbyYEnabled(bool enabled);
00169         bool getStandbyZEnabled();
00170         void setStandbyZEnabled(bool enabled);
00171         uint8_t getClockSource();
00172         void setClockSource(uint8_t source);
00173 
00174     private:
00175         uint8_t devAddr;
00176         uint8_t buffer[6];
00177 };
00178 
00179 #endif /* _ITG3200_H_ */
 All Data Structures Functions Variables