This program use the STM32L152 developement board and the MPU-9250 9-axis InvenSense movement sensor. The communication between both devices is made through I2C serial interface. This algorithm calibrates and reads data from accelerometer, gyroscope, magnetometer and the internal temperature sensor. The lecture is made each time has a new meassured value (both gyro and accel data). A comunication with a computer is made using serial interface. The user can see the data measured with 1 second update rate.

Dependencies:   mbed

Dependents:   2_MPU9250_attitude

Revision:
2:bb20d5091065
Parent:
1:61bf659e4a1f
--- a/MPU9250.h	Sun Jun 07 16:48:13 2015 +0000
+++ b/MPU9250.h	Tue Sep 01 14:06:00 2015 +0000
@@ -218,6 +218,7 @@
 float temperature;
 float SelfTest[6];
 float orientation[1];
+float magn_x, magn_y;
 
 int delt_t = 0; // used to control display output rate
 int count = 0;  // used to control display output rate
@@ -260,7 +261,7 @@
         char data_write[1];
         data_write[0] = subAddress;
         I2Cstate = i2c.write(address, data_write, 1, 1); // no stop
-        I2Cstate = i2c.read(address, data, 1, 0); 
+        I2Cstate = i2c.read(address, data, 1, 0);
         return data[0];
     }
 
@@ -452,7 +453,7 @@
   
         // reset device, reset all registers, clear gyro and accelerometer bias registers
         writeByte(MPU9250_ADDRESS, PWR_MGMT_1, 0x80); // Write a one to bit 7 reset bit; toggle reset device
-        wait(0.1);  
+        wait(0.1);
    
         // get stable time source
         // Set clock source to be PLL with x-axis gyroscope reference, bits 2:0 = 001
@@ -478,7 +479,7 @@
         uint16_t  gyrosensitivity  = 131;   // = 131 LSB/degrees/sec
         uint16_t  accelsensitivity = 16384;  // = 16384 LSB/g
 
-        // Configure FIFO to capture accelerometer and gyro data for bias calculation
+        // Configure FIFO to capture accelerometer and gyro data. This data will be used for bias calculation
         writeByte(MPU9250_ADDRESS, USER_CTRL, 0x40);   // Enable FIFO  
         writeByte(MPU9250_ADDRESS, FIFO_EN, 0x78);     // Enable gyro and accelerometer sensors for FIFO (max size 512 bytes in MPU-9250)
         wait(0.04); // accumulate 40 samples in 80 milliseconds = 480 bytes
@@ -626,7 +627,6 @@
         // Configure the accelerometer for self-test
         writeByte(MPU9250_ADDRESS, ACCEL_CONFIG, 0xE0); // Enable self test on all three axes and set accelerometer range to +/- 2 g
         writeByte(MPU9250_ADDRESS, GYRO_CONFIG, 0xE0); // Enable self test on all three axes and set gyro range to +/- 250 degrees/s
-        //delay(25); // Delay a while to let the device stabilize
         wait_ms(25); // Delay a while to let the device stabilize
 
         for( int ii = 0; ii < 200; ii++) { // get average self-test values of gyro and acclerometer
@@ -686,7 +686,6 @@
         what the magnetometer will read. A value, called the declination angle, can be applied to the magnetic direction to correct for this.
         On Valencia (Spain) this value is about 0 degrees.
         */
-        float magn_x, magn_y;
                 
         // First of all measure 3 axis magnetometer values (only X and Y axis is used):        
         readMagData(magCount);  // Read the x/y/z adc values