NOT FINISHED YET!!! My first try to get a self built fully working Quadrocopter based on an mbed, a self built frame and some other more or less cheap parts.

Dependencies:   mbed MODI2C

Files at this revision

API Documentation at this revision

Comitter:
maetugr
Date:
Wed Jun 12 10:26:18 2013 +0000
Parent:
35:2a9465fedb99
Child:
37:34917f7c10ae
Commit message:
after inserting MODI2C to get an undisturbed I2C-communication

Changed in this revision

MODI2C.lib Show annotated file Show diff for this revision Revisions of this file
Sensors/I2C_Sensor.cpp Show annotated file Show diff for this revision Revisions of this file
Sensors/I2C_Sensor.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
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MODI2C.lib	Wed Jun 12 10:26:18 2013 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/Sissors/code/MODI2C/#ff579e7e8efa
--- a/Sensors/I2C_Sensor.cpp	Mon Jun 10 20:47:01 2013 +0000
+++ b/Sensors/I2C_Sensor.cpp	Wed Jun 12 10:26:18 2013 +0000
@@ -4,9 +4,10 @@
 #define GET_I2C_WRITE_ADDRESS(ADR)  (ADR << 1&0xFE) // ADR & 1111 1110
 #define GET_I2C_READ_ADDRESS(ADR)   (ADR << 1|0x01) // ADR | 0000 0001
 
-I2C_Sensor::I2C_Sensor(PinName sda, PinName scl, char i2c_address) :  i2c(sda, scl), local("local")
+I2C_Sensor::I2C_Sensor(PinName sda, PinName scl, char i2c_address) : i2c_init(sda, scl), i2c(sda, scl), local("local")
 {
     I2C_Sensor::i2c_address = i2c_address;
+    i2c_init.frequency(400000); // standard speed
     i2c.frequency(400000); // standard speed
     //i2c.frequency(1500000); // ultrafast!
 }
@@ -27,16 +28,17 @@
     fclose(fp);
 }
 
-//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-// ATTENTION!!! the I2C option "repeated" = true is important because otherwise interrupts while bus communications cause crashes (see http://www.i2c-bus.org/repeated-start-condition/)
-//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+// ATTENTION!!! there was a problem with other interrupts disturbing the i2c communication of the chip... that's why I use I2C to initialise the sonsors and MODI2C to get the data (only made with readMultiRegister)
+// IT DIDN'T WORK STABLE IN OTHER COMBINATIONS (if someone has an idea why please let me know)
+//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 
 char I2C_Sensor::readRegister(char reg)
 {
     char value = 0;
     
-    i2c.write(i2c_address, &reg, 1, true);
-    i2c.read(i2c_address, &value, 1, true);
+    i2c_init.write(i2c_address, &reg, 1);
+    i2c_init.read(i2c_address, &value, 1);
 
     return value;
 }
@@ -44,11 +46,11 @@
 void I2C_Sensor::writeRegister(char reg, char data)
 {
     char buffer[2] = {reg, data};
-    i2c.write(i2c_address, buffer, 2, true);
+    i2c_init.write(i2c_address, buffer, 2);
 }
 
 void I2C_Sensor::readMultiRegister(char reg, char* output, int size)
 {
-    i2c.write (i2c_address, &reg, 1, true); // tell register address of the MSB get the sensor to do slave-transmit subaddress updating.
-    i2c.read  (i2c_address, output, size, true); // tell it where to store the data read
+    i2c.write (i2c_address, &reg, 1); // tell register address of the MSB get the sensor to do slave-transmit subaddress updating.
+    i2c.read  (i2c_address, output, size); // tell it where to store the data read
 }
\ No newline at end of file
--- a/Sensors/I2C_Sensor.h	Mon Jun 10 20:47:01 2013 +0000
+++ b/Sensors/I2C_Sensor.h	Wed Jun 12 10:26:18 2013 +0000
@@ -4,6 +4,7 @@
 #define I2C_Sensor_H
 
 #include "mbed.h"
+#include "MODI2C.h"
 
 class I2C_Sensor
 {           
@@ -29,7 +30,8 @@
         virtual void readraw() = 0;
         
     private:
-        I2C i2c;            // I2C-Bus
+        I2C i2c_init;       // original mbed I2C-library just to initialise the control registers
+        MODI2C i2c;         // I2C-Bus
         char i2c_address;   // address
         
         LocalFileSystem local; // file access to save calibration values
--- a/main.cpp	Mon Jun 10 20:47:01 2013 +0000
+++ b/main.cpp	Wed Jun 12 10:26:18 2013 +0000
@@ -14,7 +14,7 @@
 #define RATE            0.002                               // speed of the interrupt for Sensors and PID
 #define PPM_FREQU       495                                 // Hz Frequency of PPM Signal for ESCs (maximum <500Hz)
 #define RC_SENSITIVITY  30                                  // maximal angle from horizontal that the PID is aming for
-#define YAWSPEED        2                                   // maximal speed of yaw rotation in degree per Rate
+#define YAWSPEED        0.2                                 // maximal speed of yaw rotation in degree per Rate
 
 // RC
 #define AILERON         0
--- a/mbed.bld	Mon Jun 10 20:47:01 2013 +0000
+++ b/mbed.bld	Wed Jun 12 10:26:18 2013 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/cd19af002ccc
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/b3110cd2dd17
\ No newline at end of file