Bluepill version of mpu9250-dmp library of sparkfun

Dependencies:   MotionDriver_6_1 SparkFunMPU9250-DMP mbed-STM32F103C8T6 mbed

Fork of MPU9250-dmp by Oğuz Özdemir

Files at this revision

API Documentation at this revision

Comitter:
mbedoguz
Date:
Mon Aug 14 14:19:50 2017 +0000
Parent:
9:ef46e12b4560
Commit message:
Several informative comments and macros added.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Mon Aug 14 14:09:50 2017 +0000
+++ b/main.cpp	Mon Aug 14 14:19:50 2017 +0000
@@ -2,26 +2,34 @@
 #include "mdcompat.h"
 #include "stm32f103c8t6.h"
 //In order to compile, you should define MPU9250 in build macros
-
+//definitions
+#define DEBUG 0
+//classes
 Serial pc(SERIAL_TX,SERIAL_RX);
 DigitalOut led(LED1);
 MPU9250_DMP imu;
-unsigned char whoami[1]={0};
-unsigned char fifo_count[2]={32,32};
-unsigned char temp[1]={32};
-unsigned char outbuff[4];
-unsigned char inbuff[4];
+
+//variables
+#if DEBUG
+    unsigned char whoami[1]={0};
+    unsigned char outbuff[4];
+    unsigned char inbuff[4];
+#endif
+
 unsigned char regadd;
 char registeradress[5];
 unsigned char registerdata[]={33};
+
+//Prorotypes
 void printIMUData(void);
+
 int main() 
 {
   pc.baud(115200);
   pc.printf("Hello World\n");
   imu_init();
   stamper_init();
-#if 1//Regular program
+#if ~DEBUG//Regular program
   // Call imu.begin() to verify communication and initialize
   if (imu.begin() != INV_SUCCESS){
     while (1){
@@ -34,7 +42,7 @@
   
     if(imu.dmpBegin(DMP_FEATURE_6X_LP_QUAT | // Enable 6-axis quat
                DMP_FEATURE_GYRO_CAL, // Use gyro calibration
-              10)==INV_ERROR){ // Set DMP FIFO rate to 150 Hz
+              150)==INV_ERROR){ // Set DMP FIFO rate to 150 Hz
         pc.printf("imu.dmpBegin have failed\n");//dmpLoad function under it fails which is caused by memcmp(firmware+ii, cur, this_write) (it is located at row 2871 of inv_mpu.c)
               }
     else{
@@ -42,7 +50,7 @@
     }
     pc.printf("$GETEU,*\n");
 #endif
-#if 0//this scope is only for debugging purposes of mbed_i2c_read and write functions
+#if DEBUG //this scope is only for debugging purposes of mbed_i2c_read and write functions
     mbed_i2c_read(0x68,0x75,1,whoami);
     pc.printf("whoami=%d\n",whoami[0]);
     mbed_i2c_read(0x68,0x23,2,inbuff);
@@ -61,23 +69,24 @@
         mbed_i2c_read(0x68,(unsigned)regadd,1,registerdata);
         pc.printf("%d is gotten from serial port, data at that register is %d\n",regadd,registerdata[0]);
     }
+
   // Check for new data in the FIFO
-    if (imu.fifoAvailable()){//fifo is not being available
-        led=0;
-        wait_ms(1);
-        led=1;
-        wait_ms(1);
-        // Use dmpUpdateFifo to update the ax, gx, mx, etc. values
-        if ( imu.dmpUpdateFifo() == INV_SUCCESS){
-          // computeEulerAngles can be used -- after updating the
-          // quaternion values -- to estimate roll, pitch, and yaw
-          imu.computeEulerAngles();
-          printIMUData();
-        }
+  if (imu.fifoAvailable()){//fifo is not being available
+    led=0;
+    wait_ms(1);
+    led=1;
+    wait_ms(1);
+    // Use dmpUpdateFifo to update the ax, gx, mx, etc. values
+    if ( imu.dmpUpdateFifo() == INV_SUCCESS){
+      // computeEulerAngles can be used -- after updating the
+      // quaternion values -- to estimate roll, pitch, and yaw
+      imu.computeEulerAngles();
+      printIMUData();
     }
-    else{
-          led=0;
-    }
+  }
+  else{
+    led=0;
+  }
 }
   return 0;
 }