A project similar to http://mbed.org/users/lhiggs/code/UM6_IMU_AHRS_2012/, where I'm trying to log data from a UM6 (CH Robotics orientation sensor) and a GPS transceiver to an sd card. I've adapted LHiggs code to include ModGPS. For sum reason a soon as I pick up a gps signal the UM6 data freezes i.e. the time and gps signals continue to print out but the UM6 signals fixes on a single value.

Dependencies:   MODGPS MODSERIAL SDFileSystem mbed

Revision:
5:ac633cdbb75c
Parent:
4:8dcf0bdc25c8
Child:
6:fae3d66a4e21
--- a/main.cpp	Fri May 24 12:47:22 2013 +0000
+++ b/main.cpp	Sat May 25 12:47:06 2013 +0000
@@ -1,17 +1,19 @@
 #include "mbed.h"
 #include "SDFileSystem.h"    // SD file system header from handbook/cookbook offical mbed library
 #include "MODSERIAL.h"   
+#include "UM6_usart.h"     // UM6 USART HEADER
+#include "UM6_config.h"    // UM6 CONFIG HEADER
 
 
 //------------ system and interface setup ----------------------------//
-LocalFileSystem local("local");  // sets up local file on mbed
+//////////////////////////////////////LocalFileSystem local("local");  // sets up local file on mbed
 MODSERIAL pc(USBTX, USBRX);  // sets up serial connection to pc terminal
 
 //------------ Hardware setup ----------------------------------------//
-DigitalOut led1(LED1);    // debug LED
+DigitalOut pc_led(LED1);    // LED1 = PC SERIAL
+DigitalOut uart_led(LED2);  // LED2 = UM6 SERIAL
+DigitalOut log_led(LED3);    // debug LED
 DigitalIn enable(p10);    // enable signal for logging data to file
-AnalogIn log1(p18);       // dummy log signal1
-AnalogIn log2(p19);       // dummy log signal2
 SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed Cool Components workshop board
 
 
@@ -21,6 +23,14 @@
 int counter=0;
 int flag=0;
 
+// interupt function for processing uart messages --------------------//
+void rxCallback(MODSERIAL_IRQ_INFO *q) {
+    if (um6_uart.rxBufferGetCount() >=  MAX_PACKET_DATA) {
+        uart_led = !uart_led;  // Lights LED when uart RxBuff has > 40 bytes
+        Process_um6_packet();
+    }
+}
+
 //------------ LogData interrupt function ----------------------------//
 void LogData() {
             counter++;
@@ -30,6 +40,13 @@
 //============= Main Program =========================================//
 int main() {
     pc.baud(115200);  // baud rate to pc interface
+    um6_uart.baud(115200); // baud rate to um6 interface
+
+    t.start(); // start log time
+
+    //---- call interrupt functions -------------------------//
+    um6_uart.attach(&rxCallback, MODSERIAL::RxIrq); // attach interupt function to uart
+    tick.attach(&LogData, 0.01); // attaches LogData function to 'tick' ticker interrupt every 0.5s
     
     //---------- setup sd card -----------------------------// 
     mkdir("/sd/mydir", 0777);    
@@ -37,24 +54,35 @@
     if(fp == NULL) {
         error("Could not open file for write\n");
     }
-//    FILE *fp = fopen("/local/ticker4.csv", "w");
-    fprintf(fp,"time,counter,log1,log2 \r");
-     
-    t.start();
-    tick.attach(&LogData, 0.01); // attaches LogData function to 'tick' ticker interrupt every 0.5s
+////////////    FILE *fp = fopen("/local/log1.csv", "w");
+    fprintf(fp,"time(s),count,Yaw(deg),Accel(m/s2) \r");        
 
+    //---- main while loop ----------------------------------// 
+    //--(interrupt sets flag that causes variables to be logged)
     while(1) {
             if(flag==1) {  // prints counter value every interrupt raises flag
-                led1=1;              
-                fprintf(fp,"%.3f,%d,%f,%f \r",t.read(),counter,log1,log2);
-                pc.printf("%.3f, %d, %f, %f \n",t.read(),counter,log1,log2);
+                log_led=1;  // turns on LED3 to indicate logging               
+                float Yaw=data.Yaw;
+                float AccelX=data.Accel_Proc_X;            
+                fprintf(fp,"%.3f,%d,%f,%f \r",t.read(),counter,Yaw,AccelX);
+                pc.printf("time %.3f, count %d,Yaw %f,Accel %f \n",t.read(),counter,Yaw,AccelX);
                 flag=0;
+                pc_led = !pc_led;  // Lights LED1 when uart RxBuff has > 40 bytes     
             }    // end if(flag=1) loop
          
-            if(enable==0) {       
+            if(enable==0) {
             break;             // breaks while loop in enable switched off
             }
     } // end while(1) loop
-    fclose(fp);
-    led1=0; // turns off LED when enable switch off
-} // end main() loop
+    pc.printf(" done. ");  // prints 'done when logging is finished/enable switched off
+    log_led=0;             // turns off LED logging is finished/enable switched off
+    wait(0.5);             // debug wait for pc.printf      
+    fclose(fp);            // closes log file
+} // end main() program
+
+
+/* opening a file BEFORE calling interrupts                         OK
+   opening a file and print to it BEFORE calling interrupts         NOT OK (stops rest of program)
+   open a (local) file and print to it AFTER calling interrupts     NOT OK (stops rest of program)
+   open a (sd) file and print to it AFTER calling interrupts        OK 
+*/
\ No newline at end of file