Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed STM32L152withMPU-9250
Revision 2:bb20d5091065, committed 2015-09-01
- Comitter:
- xosuuu
- Date:
- Tue Sep 01 14:06:00 2015 +0000
- Parent:
- 1:61bf659e4a1f
- Child:
- 3:ceb5990f373f
- Commit message:
- 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.
Changed in this revision
| MPU9250.h | Show annotated file Show diff for this revision Revisions of this file |
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- 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
--- a/main.cpp Sun Jun 07 16:48:13 2015 +0000
+++ b/main.cpp Tue Sep 01 14:06:00 2015 +0000
@@ -26,6 +26,7 @@
uint32_t sumCount = 0;
char buffer[14];
uint8_t dato_leido[2];
+uint8_t whoami;
int main() {
@@ -37,7 +38,7 @@
t.start(); // Timer ON
// Read the WHO_AM_I register, this is a good test of communication
- uint8_t whoami = mpu9250.readByte(MPU9250_ADDRESS, WHO_AM_I_MPU9250);
+ whoami = mpu9250.readByte(MPU9250_ADDRESS, WHO_AM_I_MPU9250);
pc.printf("I AM 0x%x\n\r", whoami); pc.printf("I SHOULD BE 0x71\n\r");
if (I2Cstate != 0) // error on I2C
@@ -107,8 +108,7 @@
// If intPin goes high, all data registers have new data
if(mpu9250.readByte(MPU9250_ADDRESS, INT_STATUS) & 0x01) { // On interrupt, check if data ready interrupt
-
- wait(5);
+
mpu9250.readAccelData(accelCount); // Read the x/y/z adc values
// Now we'll calculate the accleration value into actual g's
if (I2Cstate != 0) //error on I2C
@@ -120,7 +120,6 @@
az = (float)accelCount[2]*aRes - accelBias[2];
}
- wait(5);
mpu9250.readGyroData(gyroCount); // Read the x/y/z adc values
// Calculate the gyro value into actual degrees per second
if (I2Cstate != 0) //error on I2C
@@ -132,7 +131,6 @@
gz = (float)gyroCount[2]*gRes - gyroBias[2];
}
- wait(5);
mpu9250.readMagData(magCount); // Read the x/y/z adc values
// Calculate the magnetometer values in milliGauss
// Include factory calibration per data sheet and user environmental corrections
@@ -144,8 +142,7 @@
my = (float)magCount[1]*mRes*magCalibration[1] - magbias[1];
mz = (float)magCount[2]*mRes*magCalibration[2] - magbias[2];
}
-
- wait(5);
+
mpu9250.getCompassOrientation(orientation);
}