yushin yamada / MPU9250

Fork of MPU9250 by yushin yamada

Files at this revision

API Documentation at this revision

Comitter:
kylongmu
Date:
Mon Jun 30 13:15:53 2014 +0000
Parent:
7:1bcd61cdbf18
Child:
9:a8733542d0fb
Commit message:
Add read all function.

Changed in this revision

MPU9250.cpp Show annotated file Show diff for this revision Revisions of this file
MPU9250.h Show annotated file Show diff for this revision Revisions of this file
--- a/MPU9250.cpp	Sun Jun 29 07:17:22 2014 +0000
+++ b/MPU9250.cpp	Mon Jun 30 13:15:53 2014 +0000
@@ -319,6 +319,43 @@
         Magnetometer[i]=data/Magnetometer_divider;
     }
 }
+void mpu9250_spi::read_all(){
+    uint8_t response[21];
+    int16_t bit_data;
+    float data;
+    int i;
+
+    //Send I2C command at first
+    WriteReg(MPUREG_I2C_SLV0_ADDR,AK8963_I2C_ADDR|READ_FLAG); //Set the I2C slave addres of AK8963 and set for read.
+    WriteReg(MPUREG_I2C_SLV0_REG, AK8963_HXL); //I2C slave 0 register address from where to begin data transfer
+    WriteReg(MPUREG_I2C_SLV0_CTRL, 0x87); //Read 7 bytes from the magnetometer
+    //must start your read from AK8963A register 0x03 and read seven bytes so that upon read of ST2 register 0x09 the AK8963A will unlatch the data registers for the next measurement.
+
+    //wait(0.001);
+    ReadRegs(MPUREG_ACCEL_XOUT_H,response,21);
+    //Get accelerometer value
+    for(i=0; i<3; i++) {
+        bit_data=((int16_t)response[i*2]<<8)|response[i*2+1];
+        data=(float)bit_data;
+        accelerometer_data[i]=data/acc_divider;
+    }
+    //Get temperature
+    bit_data=((int16_t)response[i*2]<<8)|response[i*2+1];
+    data=(float)bit_data;
+    Temperature=(data/340)+36.53;
+    //Get gyroscop value
+    for(i=4; i<7; i++) {
+        bit_data=((int16_t)response[i*2]<<8)|response[i*2+1];
+        data=(float)bit_data;
+        gyroscope_data[i-4]=data/gyro_divider;
+    }
+    //Get Magnetometer value
+    for(i=7; i<10; i++) {
+        bit_data=((int16_t)response[i*2]<<8)|response[i*2+1];
+        data=(float)bit_data;
+        Magnetometer[i-7]=data/Magnetometer_divider;
+    }
+}
 
 /*-----------------------------------------------------------------------------------------------
                                 SPI SELECT AND DESELECT
--- a/MPU9250.h	Sun Jun 29 07:17:22 2014 +0000
+++ b/MPU9250.h	Mon Jun 30 13:15:53 2014 +0000
@@ -31,6 +31,7 @@
     unsigned int whoami();
     uint8_t  AK8963_whoami();
     void AK8963_read_Magnetometer();
+    void read_all();