My fully self designed first stable working Quadrocopter Software.

Dependencies:   mbed

Dependents:   fluy343

/media/uploads/maetugr/dsc09031.jpg

Committer:
maetugr
Date:
Mon Aug 31 20:20:50 2015 +0000
Revision:
10:14390c90c3f5
before changing to MPU9250

Who changed what in which revision?

UserRevisionLine numberNew contents of line
maetugr 10:14390c90c3f5 1 // by MaEtUgR (Matthias Grob) 2015
maetugr 10:14390c90c3f5 2
maetugr 10:14390c90c3f5 3 #ifndef MPU9250_H
maetugr 10:14390c90c3f5 4 #define MPU9250_H
maetugr 10:14390c90c3f5 5
maetugr 10:14390c90c3f5 6 #include "mbed.h"
maetugr 10:14390c90c3f5 7
maetugr 10:14390c90c3f5 8 class MPU9250 {
maetugr 10:14390c90c3f5 9 public:
maetugr 10:14390c90c3f5 10 MPU9250(PinName MOSI, PinName MISO, PinName SCLK, PinName CS); // constructor, uses SPI class
maetugr 10:14390c90c3f5 11
maetugr 10:14390c90c3f5 12 // Device API
maetugr 10:14390c90c3f5 13 uint8_t getWhoami(); // get the Who am I Register (should be 0x71 = 113)
maetugr 10:14390c90c3f5 14 float getTemperature(); // get a temperature measurement in °C
maetugr 10:14390c90c3f5 15
maetugr 10:14390c90c3f5 16 void readGyro(); // read measurement data from gyrsocope
maetugr 10:14390c90c3f5 17 float Gyro[3]; // where gyrsocope measurement data is stored
maetugr 10:14390c90c3f5 18 void readAcc(); // read measurement data from accelerometer
maetugr 10:14390c90c3f5 19 float Acc[3]; // where accelerometer measurement data is stored
maetugr 10:14390c90c3f5 20
maetugr 10:14390c90c3f5 21 private:
maetugr 10:14390c90c3f5 22
maetugr 10:14390c90c3f5 23 // SPI Inteface
maetugr 10:14390c90c3f5 24 SPI spi; // SPI Bus
maetugr 10:14390c90c3f5 25 DigitalOut cs; // Slave selector for SPI-Bus (needed to start and end SPI transactions)
maetugr 10:14390c90c3f5 26
maetugr 10:14390c90c3f5 27 uint8_t readRegister8(uint8_t reg); // expressive methods to read or write the number of bits written in the name
maetugr 10:14390c90c3f5 28 uint16_t readRegister16(uint8_t reg);
maetugr 10:14390c90c3f5 29 void readRegister48(uint8_t reg, int16_t *buffer);
maetugr 10:14390c90c3f5 30 void writeRegister8(uint8_t reg, uint8_t buffer);
maetugr 10:14390c90c3f5 31
maetugr 10:14390c90c3f5 32 void readRegister(uint8_t reg, uint8_t *buffer, int length); // reads length bytes of the slave registers into buffer memory
maetugr 10:14390c90c3f5 33 void writeRegister(uint8_t reg, uint8_t *buffer, int length); // writes length bytes to the slave registers from buffer memory
maetugr 10:14390c90c3f5 34 void select(); // selects the slave for a transaction
maetugr 10:14390c90c3f5 35 void deselect(); // deselects the slave after transaction
maetugr 10:14390c90c3f5 36 };
maetugr 10:14390c90c3f5 37
maetugr 10:14390c90c3f5 38 // --------------------- Register Addresses ----------------------------------------------
maetugr 10:14390c90c3f5 39 // Mnemonic Address Description
maetugr 10:14390c90c3f5 40 #define MPU9250_SELF_TEST_X_GYRO 0x00 // Gyroscope Self-Test Registers
maetugr 10:14390c90c3f5 41 #define MPU9250_SELF_TEST_Y_GYRO 0x01 //
maetugr 10:14390c90c3f5 42 #define MPU9250_SELF_TEST_Z_GYRO 0x02 //
maetugr 10:14390c90c3f5 43 #define MPU9250_SELF_TEST_X_ACCEL 0x0D // Accelerometer Self-Test Registers
maetugr 10:14390c90c3f5 44 #define MPU9250_SELF_TEST_Y_ACCEL 0x0E //
maetugr 10:14390c90c3f5 45 #define MPU9250_SELF_TEST_Z_ACCEL 0x0F //
maetugr 10:14390c90c3f5 46 #define MPU9250_XG_OFFSET_H 0x13 // Gyro Offset Registers
maetugr 10:14390c90c3f5 47 #define MPU9250_XG_OFFSET_L 0x14 //
maetugr 10:14390c90c3f5 48 #define MPU9250_YG_OFFSET_H 0x15 //
maetugr 10:14390c90c3f5 49 #define MPU9250_YG_OFFSET_L 0x16 //
maetugr 10:14390c90c3f5 50 #define MPU9250_ZG_OFFSET_H 0x17 //
maetugr 10:14390c90c3f5 51 #define MPU9250_ZG_OFFSET_L 0x18 //
maetugr 10:14390c90c3f5 52 #define MPU9250_SMPLRT_DIV 0x19 // Sample Rate Divider
maetugr 10:14390c90c3f5 53 #define MPU9250_CONFIG 0x1A // Configuration
maetugr 10:14390c90c3f5 54 #define MPU9250_GYRO_CONFIG 0x1B // Gyroscope Configuration
maetugr 10:14390c90c3f5 55 #define MPU9250_ACCEL_CONFIG 0x1C // Accelerometer Configuration
maetugr 10:14390c90c3f5 56 #define MPU9250_ACCEL_CONFIG_2 0x1D // Accelerometer Configuration 2
maetugr 10:14390c90c3f5 57 #define MPU9250_LP_ACCEL_ODR 0x1E // Low Power Accelerometer ODR Control
maetugr 10:14390c90c3f5 58 #define MPU9250_WOM_THR 0x1F // Wake-on Motion Threshold
maetugr 10:14390c90c3f5 59 #define MPU9250_FIFO_EN 0x23 // FIFO Enable
maetugr 10:14390c90c3f5 60
maetugr 10:14390c90c3f5 61 #define MPU9250_I2C_MST_CTRL 0x24 // I2C Master Control
maetugr 10:14390c90c3f5 62 #define MPU9250_I2C_SLV0_ADDR 0x25 // I2C Slave 0 Control
maetugr 10:14390c90c3f5 63 #define MPU9250_I2C_SLV0_REG 0x26 //
maetugr 10:14390c90c3f5 64 #define MPU9250_I2C_SLV0_CTRL 0x27 //
maetugr 10:14390c90c3f5 65 #define MPU9250_I2C_SLV1_ADDR 0x28 // I2C Slave 1 Control
maetugr 10:14390c90c3f5 66 #define MPU9250_I2C_SLV1_REG 0x29 //
maetugr 10:14390c90c3f5 67 #define MPU9250_I2C_SLV1_CTRL 0x2A //
maetugr 10:14390c90c3f5 68 #define MPU9250_I2C_SLV2_ADDR 0x2B // I2C Slave 2 Control
maetugr 10:14390c90c3f5 69 #define MPU9250_I2C_SLV2_REG 0x2C //
maetugr 10:14390c90c3f5 70 #define MPU9250_I2C_SLV2_CTRL 0x2D //
maetugr 10:14390c90c3f5 71 #define MPU9250_I2C_SLV3_ADDR 0x2E // I2C Slave 3 Control
maetugr 10:14390c90c3f5 72 #define MPU9250_I2C_SLV3_REG 0x2F //
maetugr 10:14390c90c3f5 73 #define MPU9250_I2C_SLV3_CTRL 0x30 //
maetugr 10:14390c90c3f5 74 #define MPU9250_I2C_SLV4_ADDR 0x31 // I2C Slave 4 Control
maetugr 10:14390c90c3f5 75 #define MPU9250_I2C_SLV4_REG 0x32 //
maetugr 10:14390c90c3f5 76 #define MPU9250_I2C_SLV4_DO 0x33 //
maetugr 10:14390c90c3f5 77 #define MPU9250_I2C_SLV4_CTRL 0x34 //
maetugr 10:14390c90c3f5 78 #define MPU9250_I2C_SLV4_DI 0x35 //
maetugr 10:14390c90c3f5 79 #define MPU9250_I2C_MST_STATUS 0x36 // I2C Master Status
maetugr 10:14390c90c3f5 80
maetugr 10:14390c90c3f5 81 #define MPU9250_INT_PIN_CFG 0x37 // INT Pin / Bypass Enable Configuration
maetugr 10:14390c90c3f5 82 #define MPU9250_INT_ENABLE 0x38 // Interrupt Enable
maetugr 10:14390c90c3f5 83 #define MPU9250_INT_STATUS 0x3A // Interrupt Status
maetugr 10:14390c90c3f5 84
maetugr 10:14390c90c3f5 85 #define MPU9250_ACCEL_XOUT_H 0x3B // Accelerometer Measurements
maetugr 10:14390c90c3f5 86 #define MPU9250_ACCEL_XOUT_L 0x3C //
maetugr 10:14390c90c3f5 87 #define MPU9250_ACCEL_YOUT_H 0x3D //
maetugr 10:14390c90c3f5 88 #define MPU9250_ACCEL_YOUT_L 0x3E //
maetugr 10:14390c90c3f5 89 #define MPU9250_ACCEL_ZOUT_H 0x3F //
maetugr 10:14390c90c3f5 90 #define MPU9250_ACCEL_ZOUT_L 0x40 //
maetugr 10:14390c90c3f5 91 #define MPU9250_TEMP_OUT_H 0x41 // Temperature Measurement
maetugr 10:14390c90c3f5 92 #define MPU9250_TEMP_OUT_L 0x42 //
maetugr 10:14390c90c3f5 93 #define MPU9250_GYRO_XOUT_H 0x43 // Gyroscope Measurements
maetugr 10:14390c90c3f5 94 #define MPU9250_GYRO_XOUT_L 0x44 //
maetugr 10:14390c90c3f5 95 #define MPU9250_GYRO_YOUT_H 0x45 //
maetugr 10:14390c90c3f5 96 #define MPU9250_GYRO_YOUT_L 0x46 //
maetugr 10:14390c90c3f5 97 #define MPU9250_GYRO_ZOUT_H 0x47 //
maetugr 10:14390c90c3f5 98 #define MPU9250_GYRO_ZOUT_L 0x48 //
maetugr 10:14390c90c3f5 99
maetugr 10:14390c90c3f5 100 #define MPU9250_EXT_SENS_DATA_00 0x49 // External Sensor Data
maetugr 10:14390c90c3f5 101 #define MPU9250_EXT_SENS_DATA_01 0x4A //
maetugr 10:14390c90c3f5 102 #define MPU9250_EXT_SENS_DATA_02 0x4B //
maetugr 10:14390c90c3f5 103 #define MPU9250_EXT_SENS_DATA_03 0x4C //
maetugr 10:14390c90c3f5 104 #define MPU9250_EXT_SENS_DATA_04 0x4D //
maetugr 10:14390c90c3f5 105 #define MPU9250_EXT_SENS_DATA_05 0x4E //
maetugr 10:14390c90c3f5 106 #define MPU9250_EXT_SENS_DATA_06 0x4F //
maetugr 10:14390c90c3f5 107 #define MPU9250_EXT_SENS_DATA_07 0x50 //
maetugr 10:14390c90c3f5 108 #define MPU9250_EXT_SENS_DATA_08 0x51 //
maetugr 10:14390c90c3f5 109 #define MPU9250_EXT_SENS_DATA_09 0x52 //
maetugr 10:14390c90c3f5 110 #define MPU9250_EXT_SENS_DATA_10 0x53 //
maetugr 10:14390c90c3f5 111 #define MPU9250_EXT_SENS_DATA_11 0x54 //
maetugr 10:14390c90c3f5 112 #define MPU9250_EXT_SENS_DATA_12 0x55 //
maetugr 10:14390c90c3f5 113 #define MPU9250_EXT_SENS_DATA_13 0x56 //
maetugr 10:14390c90c3f5 114 #define MPU9250_EXT_SENS_DATA_14 0x57 //
maetugr 10:14390c90c3f5 115 #define MPU9250_EXT_SENS_DATA_15 0x58 //
maetugr 10:14390c90c3f5 116 #define MPU9250_EXT_SENS_DATA_16 0x59 //
maetugr 10:14390c90c3f5 117 #define MPU9250_EXT_SENS_DATA_17 0x5A //
maetugr 10:14390c90c3f5 118 #define MPU9250_EXT_SENS_DATA_18 0x5B //
maetugr 10:14390c90c3f5 119 #define MPU9250_EXT_SENS_DATA_19 0x5C //
maetugr 10:14390c90c3f5 120 #define MPU9250_EXT_SENS_DATA_20 0x5D //
maetugr 10:14390c90c3f5 121 #define MPU9250_EXT_SENS_DATA_21 0x5E //
maetugr 10:14390c90c3f5 122 #define MPU9250_EXT_SENS_DATA_22 0x5F //
maetugr 10:14390c90c3f5 123 #define MPU9250_EXT_SENS_DATA_23 0x60 //
maetugr 10:14390c90c3f5 124
maetugr 10:14390c90c3f5 125 #define MPU9250_I2C_SLV0_DO 0x63 // I2C Slave 0 Data Out
maetugr 10:14390c90c3f5 126 #define MPU9250_I2C_SLV1_DO 0x64 // I2C Slave 1 Data Out
maetugr 10:14390c90c3f5 127 #define MPU9250_I2C_SLV2_DO 0x65 // I2C Slave 2 Data Out
maetugr 10:14390c90c3f5 128 #define MPU9250_I2C_SLV3_DO 0x66 // I2C Slave 3 Data Out
maetugr 10:14390c90c3f5 129 #define MPU9250_I2C_MST_DELAY_CTRL 0x67 // I2C Master Delay Control
maetugr 10:14390c90c3f5 130 #define MPU9250_SIGNAL_PATH_RESET 0x68 // Signal Path Reset
maetugr 10:14390c90c3f5 131 #define MPU9250_MOT_DETECT_CTRL 0x69 // Accelerometer Interrupt Control
maetugr 10:14390c90c3f5 132 #define MPU9250_USER_CTRL 0x6A // User Control
maetugr 10:14390c90c3f5 133 #define MPU9250_PWR_MGMT_1 0x6B // Power Management 1
maetugr 10:14390c90c3f5 134 #define MPU9250_PWR_MGMT_2 0x6C // Power Management 2
maetugr 10:14390c90c3f5 135 #define MPU9250_FIFO_COUNTH 0x72 // FIFO Count Registers
maetugr 10:14390c90c3f5 136 #define MPU9250_FIFO_COUNTL 0x73 //
maetugr 10:14390c90c3f5 137 #define MPU9250_FIFO_R_W 0x74 // FIFO Read Write
maetugr 10:14390c90c3f5 138 #define MPU9250_WHO_AM_I 0x75 // Who Am I
maetugr 10:14390c90c3f5 139 #define MPU9250_XA_OFFSET_H 0x77 // Accelerometer Offset Registers
maetugr 10:14390c90c3f5 140 #define MPU9250_XA_OFFSET_L 0x78 //
maetugr 10:14390c90c3f5 141 #define MPU9250_YA_OFFSET_H 0x7A //
maetugr 10:14390c90c3f5 142 #define MPU9250_YA_OFFSET_L 0x7B //
maetugr 10:14390c90c3f5 143 #define MPU9250_ZA_OFFSET_H 0x7D //
maetugr 10:14390c90c3f5 144 #define MPU9250_ZA_OFFSET_L 0x7E //
maetugr 10:14390c90c3f5 145
maetugr 10:14390c90c3f5 146 #endif