MPU9250
Fork of MPU9250 by
MPU9250.h@13:02291aace2cf, 2016-08-07 (annotated)
- Committer:
- kikoaac
- Date:
- Sun Aug 07 12:47:17 2016 +0000
- Revision:
- 13:02291aace2cf
- Parent:
- 12:a70c193d8195
MPU;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kylongmu | 0:768d2e151834 | 1 | /*CODED by Qiyong Mu on 21/06/2014 |
kylongmu | 7:1bcd61cdbf18 | 2 | kylongmu@msn.com |
kylongmu | 0:768d2e151834 | 3 | */ |
kylongmu | 0:768d2e151834 | 4 | |
kylongmu | 0:768d2e151834 | 5 | |
kylongmu | 0:768d2e151834 | 6 | #ifndef mpu9250_h |
kylongmu | 0:768d2e151834 | 7 | #define mpu9250_h |
kylongmu | 0:768d2e151834 | 8 | #include "mbed.h" |
kylongmu | 0:768d2e151834 | 9 | |
kylongmu | 0:768d2e151834 | 10 | |
kylongmu | 0:768d2e151834 | 11 | class mpu9250_spi |
kylongmu | 0:768d2e151834 | 12 | { |
kylongmu | 0:768d2e151834 | 13 | SPI& spi; |
kylongmu | 0:768d2e151834 | 14 | DigitalOut cs; |
kylongmu | 0:768d2e151834 | 15 | |
kylongmu | 0:768d2e151834 | 16 | public: |
kylongmu | 0:768d2e151834 | 17 | mpu9250_spi(SPI& _spi, PinName _cs); |
kylongmu | 0:768d2e151834 | 18 | unsigned int WriteReg( uint8_t WriteAddr, uint8_t WriteData ); |
kylongmu | 2:f274ea3bced9 | 19 | unsigned int ReadReg( uint8_t WriteAddr, uint8_t WriteData ); |
kylongmu | 2:f274ea3bced9 | 20 | void ReadRegs( uint8_t ReadAddr, uint8_t *ReadBuf, unsigned int Bytes ); |
kikoaac | 12:a70c193d8195 | 21 | void get_speedrate(); |
kylongmu | 0:768d2e151834 | 22 | bool init(int sample_rate_div,int low_pass_filter); |
kylongmu | 3:f4fa24cc247d | 23 | void read_temp(); |
kylongmu | 2:f274ea3bced9 | 24 | void read_acc(); |
kylongmu | 2:f274ea3bced9 | 25 | void read_rot(); |
kylongmu | 0:768d2e151834 | 26 | unsigned int set_gyro_scale(int scale); |
kylongmu | 0:768d2e151834 | 27 | unsigned int set_acc_scale(int scale); |
kylongmu | 2:f274ea3bced9 | 28 | void calib_acc(); |
kylongmu | 11:084e8ba240c1 | 29 | void AK8963_calib_Magnetometer(); |
kylongmu | 0:768d2e151834 | 30 | void select(); |
kylongmu | 0:768d2e151834 | 31 | void deselect(); |
kylongmu | 0:768d2e151834 | 32 | unsigned int whoami(); |
kylongmu | 6:c82c48348f8c | 33 | uint8_t AK8963_whoami(); |
kylongmu | 4:79185409730f | 34 | void AK8963_read_Magnetometer(); |
kikoaac | 12:a70c193d8195 | 35 | void AK8963_setoffset(int x,double offset); |
kikoaac | 12:a70c193d8195 | 36 | double *AK8936_read_Orientation(double *getdata); |
kikoaac | 12:a70c193d8195 | 37 | |
kylongmu | 8:492028cb604e | 38 | void read_all(); |
kylongmu | 4:79185409730f | 39 | |
kylongmu | 4:79185409730f | 40 | |
kylongmu | 0:768d2e151834 | 41 | |
kylongmu | 0:768d2e151834 | 42 | float acc_divider; |
kylongmu | 0:768d2e151834 | 43 | float gyro_divider; |
kylongmu | 0:768d2e151834 | 44 | |
kylongmu | 2:f274ea3bced9 | 45 | int calib_data[3]; |
kylongmu | 11:084e8ba240c1 | 46 | float Magnetometer_ASA[3]; |
kylongmu | 11:084e8ba240c1 | 47 | |
kikoaac | 12:a70c193d8195 | 48 | double accelerometer_data[3]; |
kikoaac | 12:a70c193d8195 | 49 | double accelerometer_data_prev[3]; |
kylongmu | 3:f4fa24cc247d | 50 | float Temperature; |
kylongmu | 2:f274ea3bced9 | 51 | float gyroscope_data[3]; |
kylongmu | 4:79185409730f | 52 | float Magnetometer[3]; |
kikoaac | 12:a70c193d8195 | 53 | float Magnetometer_offset[3]; |
kikoaac | 12:a70c193d8195 | 54 | double speed[3]; |
kikoaac | 12:a70c193d8195 | 55 | double meter[3]; |
kikoaac | 12:a70c193d8195 | 56 | float angle_acc[3]; |
kikoaac | 12:a70c193d8195 | 57 | short offset_gyro[3]; |
kikoaac | 12:a70c193d8195 | 58 | short rate[3]; |
kikoaac | 12:a70c193d8195 | 59 | |
kikoaac | 12:a70c193d8195 | 60 | void set(float time=0.0001 , float time2=0.001){sampleTimeSpeed=time;sampleTimeMeter=time2;} |
kikoaac | 12:a70c193d8195 | 61 | double freefallSpeedSet(); double freefallSpeedGet(); |
kikoaac | 12:a70c193d8195 | 62 | double freefallMeterSet(); double freefallMeterGet(); |
kikoaac | 12:a70c193d8195 | 63 | |
kikoaac | 12:a70c193d8195 | 64 | void SpeedSet(); |
kikoaac | 12:a70c193d8195 | 65 | void MeterSet(); |
kikoaac | 12:a70c193d8195 | 66 | |
kikoaac | 12:a70c193d8195 | 67 | void Filter(); |
kikoaac | 12:a70c193d8195 | 68 | double VectolGet();double VectolSet(); |
kikoaac | 12:a70c193d8195 | 69 | |
kikoaac | 12:a70c193d8195 | 70 | void MPU_setup(); |
kikoaac | 12:a70c193d8195 | 71 | void MPU_setnum(int Num=500,float time=0.0001,double rate=0.00390635);//set data member |
kikoaac | 12:a70c193d8195 | 72 | |
kikoaac | 12:a70c193d8195 | 73 | void get_angle_acc(); |
kikoaac | 12:a70c193d8195 | 74 | void get_rate(); |
kikoaac | 12:a70c193d8195 | 75 | void set_angle();//set always [time] |
kikoaac | 12:a70c193d8195 | 76 | void newset_angle(double ANG_x,double ANG_y,double ANG_z); |
kikoaac | 12:a70c193d8195 | 77 | void get_angle(double *x,double *y,double *z); |
kikoaac | 12:a70c193d8195 | 78 | |
kikoaac | 12:a70c193d8195 | 79 | void set_noise(); |
kikoaac | 12:a70c193d8195 | 80 | void set_offset(); |
kikoaac | 12:a70c193d8195 | 81 | void set_angleoffset(); |
kikoaac | 12:a70c193d8195 | 82 | short ratespeed[3]; |
kikoaac | 12:a70c193d8195 | 83 | short ratemeter[3]; |
kikoaac | 12:a70c193d8195 | 84 | double Synthesis_speed[3],kalman_speed[3],comp_speed[3]; |
kikoaac | 12:a70c193d8195 | 85 | double Synthesis_meter[3],kalman_meter[3],comp_meter[3]; |
kikoaac | 12:a70c193d8195 | 86 | double angle[3],Synthesis_angle[3],kalman_angle[3],comp_angle[3]; |
kylongmu | 0:768d2e151834 | 87 | private: |
kylongmu | 0:768d2e151834 | 88 | PinName _CS_pin; |
kylongmu | 0:768d2e151834 | 89 | PinName _SO_pin; |
kylongmu | 0:768d2e151834 | 90 | PinName _SCK_pin; |
kylongmu | 0:768d2e151834 | 91 | float _error; |
kikoaac | 12:a70c193d8195 | 92 | Timer angleT; |
kikoaac | 12:a70c193d8195 | 93 | Timer speedT; |
kikoaac | 12:a70c193d8195 | 94 | Timer meterT; |
kikoaac | 12:a70c193d8195 | 95 | |
kikoaac | 12:a70c193d8195 | 96 | //ACC ADXL345 |
kikoaac | 12:a70c193d8195 | 97 | int x_acc,y_acc,z_acc,sampleNum; |
kikoaac | 12:a70c193d8195 | 98 | double x_offset,y_offset,z_offset; |
kikoaac | 12:a70c193d8195 | 99 | float gx,gy,gz,xnoise,ynoise,znoise; |
kikoaac | 12:a70c193d8195 | 100 | //GYALO L3GD20 |
kikoaac | 12:a70c193d8195 | 101 | double Rate; |
kikoaac | 12:a70c193d8195 | 102 | double sampleTime; |
kikoaac | 12:a70c193d8195 | 103 | float noise[3]; |
kikoaac | 12:a70c193d8195 | 104 | short offset[3];short prev_rate[3]; |
kikoaac | 12:a70c193d8195 | 105 | |
kikoaac | 12:a70c193d8195 | 106 | double t[3]; |
kikoaac | 12:a70c193d8195 | 107 | short tempDATA_ACC[3],tempDATA_ANGLE[3]; |
kikoaac | 12:a70c193d8195 | 108 | double offset_angle[3]; |
kikoaac | 12:a70c193d8195 | 109 | |
kikoaac | 12:a70c193d8195 | 110 | short prev_ratespeed[3],prev_speed[3]; |
kikoaac | 12:a70c193d8195 | 111 | short prev_ratemeter[3],prev_meter[3]; |
kikoaac | 12:a70c193d8195 | 112 | double real_acc[3]; |
kikoaac | 12:a70c193d8195 | 113 | short acc[3]; |
kikoaac | 12:a70c193d8195 | 114 | double filter_acc[3]; |
kikoaac | 12:a70c193d8195 | 115 | |
kikoaac | 12:a70c193d8195 | 116 | int sampleTimeSpeed,sampleTimeMeter; |
kikoaac | 12:a70c193d8195 | 117 | |
kikoaac | 12:a70c193d8195 | 118 | class kalman |
kikoaac | 12:a70c193d8195 | 119 | { |
kikoaac | 12:a70c193d8195 | 120 | public: |
kikoaac | 12:a70c193d8195 | 121 | kalman(void); |
kikoaac | 12:a70c193d8195 | 122 | double getAngle(double newAngle, double newRate, double dt); |
kikoaac | 12:a70c193d8195 | 123 | |
kikoaac | 12:a70c193d8195 | 124 | void setAngle(double newAngle); |
kikoaac | 12:a70c193d8195 | 125 | void setQangle(double newQ_angle); |
kikoaac | 12:a70c193d8195 | 126 | void setQgyroBias(double newQ_gyroBias); |
kikoaac | 12:a70c193d8195 | 127 | void setRangle(double newR_angle); |
kikoaac | 12:a70c193d8195 | 128 | |
kikoaac | 12:a70c193d8195 | 129 | double getRate(void); |
kikoaac | 12:a70c193d8195 | 130 | double getQangle(void); |
kikoaac | 12:a70c193d8195 | 131 | double getQbias(void); |
kikoaac | 12:a70c193d8195 | 132 | double getRangle(void); |
kikoaac | 12:a70c193d8195 | 133 | |
kikoaac | 12:a70c193d8195 | 134 | |
kikoaac | 12:a70c193d8195 | 135 | private: |
kikoaac | 12:a70c193d8195 | 136 | double P[2][2]; //error covariance matrix |
kikoaac | 12:a70c193d8195 | 137 | double K[2]; //kalman gain |
kikoaac | 12:a70c193d8195 | 138 | double y; //angle difference |
kikoaac | 12:a70c193d8195 | 139 | double S; //estimation error |
kikoaac | 12:a70c193d8195 | 140 | |
kikoaac | 12:a70c193d8195 | 141 | double rate; //rate in deg/s |
kikoaac | 12:a70c193d8195 | 142 | double angle; //kalman angle |
kikoaac | 12:a70c193d8195 | 143 | double bias; //kalman gyro bias |
kikoaac | 12:a70c193d8195 | 144 | |
kikoaac | 12:a70c193d8195 | 145 | double Q_angle; //process noise variance for the angle of the accelerometer |
kikoaac | 12:a70c193d8195 | 146 | double Q_gyroBias; //process noise variance for the gyroscope bias |
kikoaac | 12:a70c193d8195 | 147 | double R_angle; //measurement noise variance |
kikoaac | 12:a70c193d8195 | 148 | }; |
kikoaac | 12:a70c193d8195 | 149 | kalman kalmaspeed[3]; |
kikoaac | 12:a70c193d8195 | 150 | kalman kalmameter[3]; |
kikoaac | 12:a70c193d8195 | 151 | //KALMAN |
kikoaac | 12:a70c193d8195 | 152 | kalman kalma[3]; |
kylongmu | 0:768d2e151834 | 153 | }; |
kylongmu | 0:768d2e151834 | 154 | |
kylongmu | 0:768d2e151834 | 155 | #endif |
kylongmu | 0:768d2e151834 | 156 | |
kylongmu | 0:768d2e151834 | 157 | |
kylongmu | 0:768d2e151834 | 158 | |
kylongmu | 0:768d2e151834 | 159 | // mpu9250 registers |
kylongmu | 0:768d2e151834 | 160 | #define MPUREG_XG_OFFS_TC 0x00 |
kylongmu | 0:768d2e151834 | 161 | #define MPUREG_YG_OFFS_TC 0x01 |
kylongmu | 0:768d2e151834 | 162 | #define MPUREG_ZG_OFFS_TC 0x02 |
kylongmu | 0:768d2e151834 | 163 | #define MPUREG_X_FINE_GAIN 0x03 |
kylongmu | 0:768d2e151834 | 164 | #define MPUREG_Y_FINE_GAIN 0x04 |
kylongmu | 0:768d2e151834 | 165 | #define MPUREG_Z_FINE_GAIN 0x05 |
kylongmu | 0:768d2e151834 | 166 | #define MPUREG_XA_OFFS_H 0x06 |
kylongmu | 0:768d2e151834 | 167 | #define MPUREG_XA_OFFS_L 0x07 |
kylongmu | 0:768d2e151834 | 168 | #define MPUREG_YA_OFFS_H 0x08 |
kylongmu | 0:768d2e151834 | 169 | #define MPUREG_YA_OFFS_L 0x09 |
kylongmu | 0:768d2e151834 | 170 | #define MPUREG_ZA_OFFS_H 0x0A |
kylongmu | 0:768d2e151834 | 171 | #define MPUREG_ZA_OFFS_L 0x0B |
kylongmu | 0:768d2e151834 | 172 | #define MPUREG_PRODUCT_ID 0x0C |
kylongmu | 0:768d2e151834 | 173 | #define MPUREG_SELF_TEST_X 0x0D |
kylongmu | 0:768d2e151834 | 174 | #define MPUREG_SELF_TEST_Y 0x0E |
kylongmu | 0:768d2e151834 | 175 | #define MPUREG_SELF_TEST_Z 0x0F |
kylongmu | 0:768d2e151834 | 176 | #define MPUREG_SELF_TEST_A 0x10 |
kylongmu | 0:768d2e151834 | 177 | #define MPUREG_XG_OFFS_USRH 0x13 |
kylongmu | 0:768d2e151834 | 178 | #define MPUREG_XG_OFFS_USRL 0x14 |
kylongmu | 0:768d2e151834 | 179 | #define MPUREG_YG_OFFS_USRH 0x15 |
kylongmu | 0:768d2e151834 | 180 | #define MPUREG_YG_OFFS_USRL 0x16 |
kylongmu | 0:768d2e151834 | 181 | #define MPUREG_ZG_OFFS_USRH 0x17 |
kylongmu | 0:768d2e151834 | 182 | #define MPUREG_ZG_OFFS_USRL 0x18 |
kylongmu | 0:768d2e151834 | 183 | #define MPUREG_SMPLRT_DIV 0x19 |
kylongmu | 0:768d2e151834 | 184 | #define MPUREG_CONFIG 0x1A |
kylongmu | 0:768d2e151834 | 185 | #define MPUREG_GYRO_CONFIG 0x1B |
kylongmu | 0:768d2e151834 | 186 | #define MPUREG_ACCEL_CONFIG 0x1C |
kylongmu | 0:768d2e151834 | 187 | #define MPUREG_ACCEL_CONFIG_2 0x1D |
kylongmu | 0:768d2e151834 | 188 | #define MPUREG_LP_ACCEL_ODR 0x1E |
kylongmu | 0:768d2e151834 | 189 | #define MPUREG_MOT_THR 0x1F |
kylongmu | 0:768d2e151834 | 190 | #define MPUREG_FIFO_EN 0x23 |
kylongmu | 0:768d2e151834 | 191 | #define MPUREG_I2C_MST_CTRL 0x24 |
kylongmu | 0:768d2e151834 | 192 | #define MPUREG_I2C_SLV0_ADDR 0x25 |
kylongmu | 0:768d2e151834 | 193 | #define MPUREG_I2C_SLV0_REG 0x26 |
kylongmu | 0:768d2e151834 | 194 | #define MPUREG_I2C_SLV0_CTRL 0x27 |
kylongmu | 0:768d2e151834 | 195 | #define MPUREG_I2C_SLV1_ADDR 0x28 |
kylongmu | 0:768d2e151834 | 196 | #define MPUREG_I2C_SLV1_REG 0x29 |
kylongmu | 0:768d2e151834 | 197 | #define MPUREG_I2C_SLV1_CTRL 0x2A |
kylongmu | 0:768d2e151834 | 198 | #define MPUREG_I2C_SLV2_ADDR 0x2B |
kylongmu | 0:768d2e151834 | 199 | #define MPUREG_I2C_SLV2_REG 0x2C |
kylongmu | 0:768d2e151834 | 200 | #define MPUREG_I2C_SLV2_CTRL 0x2D |
kylongmu | 0:768d2e151834 | 201 | #define MPUREG_I2C_SLV3_ADDR 0x2E |
kylongmu | 0:768d2e151834 | 202 | #define MPUREG_I2C_SLV3_REG 0x2F |
kylongmu | 0:768d2e151834 | 203 | #define MPUREG_I2C_SLV3_CTRL 0x30 |
kylongmu | 0:768d2e151834 | 204 | #define MPUREG_I2C_SLV4_ADDR 0x31 |
kylongmu | 0:768d2e151834 | 205 | #define MPUREG_I2C_SLV4_REG 0x32 |
kylongmu | 0:768d2e151834 | 206 | #define MPUREG_I2C_SLV4_DO 0x33 |
kylongmu | 0:768d2e151834 | 207 | #define MPUREG_I2C_SLV4_CTRL 0x34 |
kylongmu | 0:768d2e151834 | 208 | #define MPUREG_I2C_SLV4_DI 0x35 |
kylongmu | 0:768d2e151834 | 209 | #define MPUREG_I2C_MST_STATUS 0x36 |
kylongmu | 0:768d2e151834 | 210 | #define MPUREG_INT_PIN_CFG 0x37 |
kylongmu | 0:768d2e151834 | 211 | #define MPUREG_INT_ENABLE 0x38 |
kylongmu | 0:768d2e151834 | 212 | #define MPUREG_ACCEL_XOUT_H 0x3B |
kylongmu | 0:768d2e151834 | 213 | #define MPUREG_ACCEL_XOUT_L 0x3C |
kylongmu | 0:768d2e151834 | 214 | #define MPUREG_ACCEL_YOUT_H 0x3D |
kylongmu | 0:768d2e151834 | 215 | #define MPUREG_ACCEL_YOUT_L 0x3E |
kylongmu | 0:768d2e151834 | 216 | #define MPUREG_ACCEL_ZOUT_H 0x3F |
kylongmu | 0:768d2e151834 | 217 | #define MPUREG_ACCEL_ZOUT_L 0x40 |
kylongmu | 0:768d2e151834 | 218 | #define MPUREG_TEMP_OUT_H 0x41 |
kylongmu | 0:768d2e151834 | 219 | #define MPUREG_TEMP_OUT_L 0x42 |
kylongmu | 0:768d2e151834 | 220 | #define MPUREG_GYRO_XOUT_H 0x43 |
kylongmu | 0:768d2e151834 | 221 | #define MPUREG_GYRO_XOUT_L 0x44 |
kylongmu | 0:768d2e151834 | 222 | #define MPUREG_GYRO_YOUT_H 0x45 |
kylongmu | 0:768d2e151834 | 223 | #define MPUREG_GYRO_YOUT_L 0x46 |
kylongmu | 0:768d2e151834 | 224 | #define MPUREG_GYRO_ZOUT_H 0x47 |
kylongmu | 0:768d2e151834 | 225 | #define MPUREG_GYRO_ZOUT_L 0x48 |
kylongmu | 0:768d2e151834 | 226 | #define MPUREG_EXT_SENS_DATA_00 0x49 |
kylongmu | 0:768d2e151834 | 227 | #define MPUREG_EXT_SENS_DATA_01 0x4A |
kylongmu | 0:768d2e151834 | 228 | #define MPUREG_EXT_SENS_DATA_02 0x4B |
kylongmu | 0:768d2e151834 | 229 | #define MPUREG_EXT_SENS_DATA_03 0x4C |
kylongmu | 0:768d2e151834 | 230 | #define MPUREG_EXT_SENS_DATA_04 0x4D |
kylongmu | 0:768d2e151834 | 231 | #define MPUREG_EXT_SENS_DATA_05 0x4E |
kylongmu | 0:768d2e151834 | 232 | #define MPUREG_EXT_SENS_DATA_06 0x4F |
kylongmu | 0:768d2e151834 | 233 | #define MPUREG_EXT_SENS_DATA_07 0x50 |
kylongmu | 0:768d2e151834 | 234 | #define MPUREG_EXT_SENS_DATA_08 0x51 |
kylongmu | 0:768d2e151834 | 235 | #define MPUREG_EXT_SENS_DATA_09 0x52 |
kylongmu | 0:768d2e151834 | 236 | #define MPUREG_EXT_SENS_DATA_10 0x53 |
kylongmu | 0:768d2e151834 | 237 | #define MPUREG_EXT_SENS_DATA_11 0x54 |
kylongmu | 0:768d2e151834 | 238 | #define MPUREG_EXT_SENS_DATA_12 0x55 |
kylongmu | 0:768d2e151834 | 239 | #define MPUREG_EXT_SENS_DATA_13 0x56 |
kylongmu | 0:768d2e151834 | 240 | #define MPUREG_EXT_SENS_DATA_14 0x57 |
kylongmu | 0:768d2e151834 | 241 | #define MPUREG_EXT_SENS_DATA_15 0x58 |
kylongmu | 0:768d2e151834 | 242 | #define MPUREG_EXT_SENS_DATA_16 0x59 |
kylongmu | 0:768d2e151834 | 243 | #define MPUREG_EXT_SENS_DATA_17 0x5A |
kylongmu | 0:768d2e151834 | 244 | #define MPUREG_EXT_SENS_DATA_18 0x5B |
kylongmu | 0:768d2e151834 | 245 | #define MPUREG_EXT_SENS_DATA_19 0x5C |
kylongmu | 0:768d2e151834 | 246 | #define MPUREG_EXT_SENS_DATA_20 0x5D |
kylongmu | 0:768d2e151834 | 247 | #define MPUREG_EXT_SENS_DATA_21 0x5E |
kylongmu | 0:768d2e151834 | 248 | #define MPUREG_EXT_SENS_DATA_22 0x5F |
kylongmu | 0:768d2e151834 | 249 | #define MPUREG_EXT_SENS_DATA_23 0x60 |
kylongmu | 0:768d2e151834 | 250 | #define MPUREG_I2C_SLV0_DO 0x63 |
kylongmu | 0:768d2e151834 | 251 | #define MPUREG_I2C_SLV1_DO 0x64 |
kylongmu | 0:768d2e151834 | 252 | #define MPUREG_I2C_SLV2_DO 0x65 |
kylongmu | 0:768d2e151834 | 253 | #define MPUREG_I2C_SLV3_DO 0x66 |
kylongmu | 0:768d2e151834 | 254 | #define MPUREG_I2C_MST_DELAY_CTRL 0x67 |
kylongmu | 0:768d2e151834 | 255 | #define MPUREG_SIGNAL_PATH_RESET 0x68 |
kylongmu | 0:768d2e151834 | 256 | #define MPUREG_MOT_DETECT_CTRL 0x69 |
kylongmu | 0:768d2e151834 | 257 | #define MPUREG_USER_CTRL 0x6A |
kylongmu | 0:768d2e151834 | 258 | #define MPUREG_PWR_MGMT_1 0x6B |
kylongmu | 0:768d2e151834 | 259 | #define MPUREG_PWR_MGMT_2 0x6C |
kylongmu | 0:768d2e151834 | 260 | #define MPUREG_BANK_SEL 0x6D |
kylongmu | 0:768d2e151834 | 261 | #define MPUREG_MEM_START_ADDR 0x6E |
kylongmu | 0:768d2e151834 | 262 | #define MPUREG_MEM_R_W 0x6F |
kylongmu | 0:768d2e151834 | 263 | #define MPUREG_DMP_CFG_1 0x70 |
kylongmu | 0:768d2e151834 | 264 | #define MPUREG_DMP_CFG_2 0x71 |
kylongmu | 0:768d2e151834 | 265 | #define MPUREG_FIFO_COUNTH 0x72 |
kylongmu | 0:768d2e151834 | 266 | #define MPUREG_FIFO_COUNTL 0x73 |
kylongmu | 0:768d2e151834 | 267 | #define MPUREG_FIFO_R_W 0x74 |
kylongmu | 0:768d2e151834 | 268 | #define MPUREG_WHOAMI 0x75 |
kylongmu | 0:768d2e151834 | 269 | #define MPUREG_XA_OFFSET_H 0x77 |
kylongmu | 0:768d2e151834 | 270 | #define MPUREG_XA_OFFSET_L 0x78 |
kylongmu | 0:768d2e151834 | 271 | #define MPUREG_YA_OFFSET_H 0x7A |
kylongmu | 0:768d2e151834 | 272 | #define MPUREG_YA_OFFSET_L 0x7B |
kylongmu | 0:768d2e151834 | 273 | #define MPUREG_ZA_OFFSET_H 0x7D |
kylongmu | 0:768d2e151834 | 274 | #define MPUREG_ZA_OFFSET_L 0x7E |
kylongmu | 0:768d2e151834 | 275 | /* ---- AK8963 Reg In MPU9250 ----------------------------------------------- */ |
kylongmu | 0:768d2e151834 | 276 | |
kylongmu | 5:f15d1d9d1561 | 277 | #define AK8963_I2C_ADDR 0x0c//0x18 |
kylongmu | 0:768d2e151834 | 278 | #define AK8963_Device_ID 0x48 |
kylongmu | 0:768d2e151834 | 279 | |
kylongmu | 0:768d2e151834 | 280 | // Read-only Reg |
kylongmu | 0:768d2e151834 | 281 | #define AK8963_WIA 0x00 |
kylongmu | 0:768d2e151834 | 282 | #define AK8963_INFO 0x01 |
kylongmu | 0:768d2e151834 | 283 | #define AK8963_ST1 0x02 |
kylongmu | 0:768d2e151834 | 284 | #define AK8963_HXL 0x03 |
kylongmu | 0:768d2e151834 | 285 | #define AK8963_HXH 0x04 |
kylongmu | 0:768d2e151834 | 286 | #define AK8963_HYL 0x05 |
kylongmu | 0:768d2e151834 | 287 | #define AK8963_HYH 0x06 |
kylongmu | 0:768d2e151834 | 288 | #define AK8963_HZL 0x07 |
kylongmu | 0:768d2e151834 | 289 | #define AK8963_HZH 0x08 |
kylongmu | 0:768d2e151834 | 290 | #define AK8963_ST2 0x09 |
kylongmu | 0:768d2e151834 | 291 | // Write/Read Reg |
kylongmu | 0:768d2e151834 | 292 | #define AK8963_CNTL1 0x0A |
kylongmu | 0:768d2e151834 | 293 | #define AK8963_CNTL2 0x0B |
kylongmu | 0:768d2e151834 | 294 | #define AK8963_ASTC 0x0C |
kylongmu | 0:768d2e151834 | 295 | #define AK8963_TS1 0x0D |
kylongmu | 0:768d2e151834 | 296 | #define AK8963_TS2 0x0E |
kylongmu | 0:768d2e151834 | 297 | #define AK8963_I2CDIS 0x0F |
kylongmu | 0:768d2e151834 | 298 | // Read-only Reg ( ROM ) |
kylongmu | 0:768d2e151834 | 299 | #define AK8963_ASAX 0x10 |
kylongmu | 0:768d2e151834 | 300 | #define AK8963_ASAY 0x11 |
kylongmu | 0:768d2e151834 | 301 | #define AK8963_ASAZ 0x12 |
kylongmu | 0:768d2e151834 | 302 | |
kylongmu | 0:768d2e151834 | 303 | // Configuration bits mpu9250 |
kylongmu | 0:768d2e151834 | 304 | #define BIT_SLEEP 0x40 |
kylongmu | 0:768d2e151834 | 305 | #define BIT_H_RESET 0x80 |
kylongmu | 0:768d2e151834 | 306 | #define BITS_CLKSEL 0x07 |
kylongmu | 0:768d2e151834 | 307 | #define MPU_CLK_SEL_PLLGYROX 0x01 |
kylongmu | 0:768d2e151834 | 308 | #define MPU_CLK_SEL_PLLGYROZ 0x03 |
kylongmu | 0:768d2e151834 | 309 | #define MPU_EXT_SYNC_GYROX 0x02 |
kylongmu | 0:768d2e151834 | 310 | #define BITS_FS_250DPS 0x00 |
kylongmu | 0:768d2e151834 | 311 | #define BITS_FS_500DPS 0x08 |
kylongmu | 0:768d2e151834 | 312 | #define BITS_FS_1000DPS 0x10 |
kylongmu | 0:768d2e151834 | 313 | #define BITS_FS_2000DPS 0x18 |
kylongmu | 0:768d2e151834 | 314 | #define BITS_FS_2G 0x00 |
kylongmu | 0:768d2e151834 | 315 | #define BITS_FS_4G 0x08 |
kylongmu | 0:768d2e151834 | 316 | #define BITS_FS_8G 0x10 |
kylongmu | 0:768d2e151834 | 317 | #define BITS_FS_16G 0x18 |
kylongmu | 0:768d2e151834 | 318 | #define BITS_FS_MASK 0x18 |
kylongmu | 0:768d2e151834 | 319 | #define BITS_DLPF_CFG_256HZ_NOLPF2 0x00 |
kylongmu | 0:768d2e151834 | 320 | #define BITS_DLPF_CFG_188HZ 0x01 |
kylongmu | 0:768d2e151834 | 321 | #define BITS_DLPF_CFG_98HZ 0x02 |
kylongmu | 0:768d2e151834 | 322 | #define BITS_DLPF_CFG_42HZ 0x03 |
kylongmu | 0:768d2e151834 | 323 | #define BITS_DLPF_CFG_20HZ 0x04 |
kylongmu | 0:768d2e151834 | 324 | #define BITS_DLPF_CFG_10HZ 0x05 |
kylongmu | 0:768d2e151834 | 325 | #define BITS_DLPF_CFG_5HZ 0x06 |
kylongmu | 0:768d2e151834 | 326 | #define BITS_DLPF_CFG_2100HZ_NOLPF 0x07 |
kylongmu | 0:768d2e151834 | 327 | #define BITS_DLPF_CFG_MASK 0x07 |
kylongmu | 0:768d2e151834 | 328 | #define BIT_INT_ANYRD_2CLEAR 0x10 |
kylongmu | 0:768d2e151834 | 329 | #define BIT_RAW_RDY_EN 0x01 |
kylongmu | 0:768d2e151834 | 330 | #define BIT_I2C_IF_DIS 0x10 |
kylongmu | 0:768d2e151834 | 331 | |
kylongmu | 0:768d2e151834 | 332 | #define READ_FLAG 0x80 |
kylongmu | 0:768d2e151834 | 333 | |
kylongmu | 0:768d2e151834 | 334 | /* ---- Sensitivity --------------------------------------------------------- */ |
kylongmu | 0:768d2e151834 | 335 | |
kylongmu | 0:768d2e151834 | 336 | #define MPU9250A_2g ((float)0.000061035156f) // 0.000061035156 g/LSB |
kylongmu | 0:768d2e151834 | 337 | #define MPU9250A_4g ((float)0.000122070312f) // 0.000122070312 g/LSB |
kylongmu | 0:768d2e151834 | 338 | #define MPU9250A_8g ((float)0.000244140625f) // 0.000244140625 g/LSB |
kylongmu | 0:768d2e151834 | 339 | #define MPU9250A_16g ((float)0.000488281250f) // 0.000488281250 g/LSB |
kylongmu | 0:768d2e151834 | 340 | |
kylongmu | 0:768d2e151834 | 341 | #define MPU9250G_250dps ((float)0.007633587786f) // 0.007633587786 dps/LSB |
kylongmu | 0:768d2e151834 | 342 | #define MPU9250G_500dps ((float)0.015267175572f) // 0.015267175572 dps/LSB |
kylongmu | 0:768d2e151834 | 343 | #define MPU9250G_1000dps ((float)0.030487804878f) // 0.030487804878 dps/LSB |
kylongmu | 0:768d2e151834 | 344 | #define MPU9250G_2000dps ((float)0.060975609756f) // 0.060975609756 dps/LSB |
kylongmu | 0:768d2e151834 | 345 | |
kylongmu | 0:768d2e151834 | 346 | #define MPU9250M_4800uT ((float)0.6f) // 0.6 uT/LSB |
kylongmu | 0:768d2e151834 | 347 | |
kylongmu | 0:768d2e151834 | 348 | #define MPU9250T_85degC ((float)0.002995177763f) // 0.002995177763 degC/LSB |
kylongmu | 0:768d2e151834 | 349 | |
kylongmu | 11:084e8ba240c1 | 350 | #define Magnetometer_Sensitivity_Scale_Factor ((float)0.15f) |