MPU6050 FreeIMU library

Dependents:   FreeIMU FreeIMU_external_magnetometer

Fork of MPU6050_tmp by Aloïs Wolff

Async MPU6050 library

My port of the MPU6050 library samples the chip at 500Hz using Timer. Async I2C is achieved using a custom I2C library, which supports I2C calls from interrupts. Link given below:

Import libraryMODI2C

Improvements to Olieman's MODI2C library. Supports calls from IRQ.

Difference between this port and the Arduino MPU6050 library

The getMotion6 function only returns a copy of the last obtained readings, which is sampled at a frequency of 500Hz (adjustable). Hence it can be called at any frequency without taxing the I2C.

Files at this revision

API Documentation at this revision

Comitter:
tyftyftyf
Date:
Mon Dec 23 08:34:58 2013 +0000
Parent:
9:d879deb55ae1
Child:
11:9549be34fa7f
Commit message:
Fixed a silly pointer error

Changed in this revision

I2Cdev.cpp Show annotated file Show diff for this revision Revisions of this file
I2Cdev.h Show annotated file Show diff for this revision Revisions of this file
--- a/I2Cdev.cpp	Sat Nov 09 08:51:07 2013 +0000
+++ b/I2Cdev.cpp	Mon Dec 23 08:34:58 2013 +0000
@@ -262,31 +262,25 @@
 
 bool I2Cdev::writeBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_t *data)
 {
-    //i2c.start();
-    //i2c.write(devAddr<<1);
-    //i2c.write(regAddr);
-    //for(int i = 0; i < length; i++) {
-    //    i2c.write(data[i]);
-    //}
-    //i2c.stop();
     char* mem = NULL;
-    mem = allocbuffer();//(char*)malloc(length+1);
+    mem = allocbuffer();
     *mem = regAddr;
     memcpy(mem+1, data, length);
     
-    i2c.write(devAddr, mem, length+1, &writefinhdl, mem);
+    i2c.write(devAddr, mem, length+1, &writefinhdl, this);
     return true;
 }
 
 char *I2Cdev::allocbuffer(){
     char *buff = (char *)pool.alloc();
+    while (buff==NULL) buff = (char *)pool.alloc();
     queue.put(buff);
     return buff;
 }
 
 void I2Cdev::freebuffer(){
     osEvent evt = queue.get(0);
-    pool.free((char(*)[20])evt.value.p);
+    pool.free((char(*)[14])evt.value.p);
 }
 
 bool I2Cdev::writeWords(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint16_t *data)
--- a/I2Cdev.h	Sat Nov 09 08:51:07 2013 +0000
+++ b/I2Cdev.h	Mon Dec 23 08:34:58 2013 +0000
@@ -52,8 +52,8 @@
         char* allocbuffer();
         void freebuffer();
         
-        MemoryPool<char[20], 20> pool;
-        Queue<char, 20> queue;
+        MemoryPool<char[14], 16> pool;
+        Queue<char, 16> queue;
 };
 
 #endif
\ No newline at end of file