This example establishes a transparent link between the mbed serial port and the gps I2C on the C027. You can use it to use the standard u-blox tools such as u-center. These tools can then connect to the serial port and talk directly to the GPS receiver. Baudrate should be set to 9600 baud and is fixed. m-center can be downloaded from u-blox website following this link: http://www.u-blox.com/en/evaluation-tools-a-software/u-center/u-center.html

Dependencies:   mbed

Fork of C027_GPSTransparentSerial by u-blox

Install mbed Windows Drivers

Make sure you installed the drivers on your windows PC to get the virtual serial port. A installation guideline and the drivers can be found in the following wiki page. /handbook/Windows-serial-configuration

Revision:
5:598a573e3ad3
Parent:
4:0e065a08144b
Child:
6:5a8fd99e6a09
--- a/main.cpp	Wed Nov 06 10:49:39 2013 +0000
+++ b/main.cpp	Thu Nov 21 14:12:14 2013 +0000
@@ -3,52 +3,61 @@
 
 int main()
 {
+    Timer tmr;
+    tmr.start();
     C027 c027;
     c027.gpsPower(true);
 
     // open the gps i2c port
     I2C gps(GPSSDA, GPSSCL);
+    gps.frequency(100000);
 
     // open the PC serial port and (use the same baudrate)
     Serial pc(USBTX, USBRX);
     pc.baud(GPSBAUD);
-
+    
+    int s = 0;
+    int i = 0;
+    int o = 1; 
+    char in[1024];
+    char out[1024] = { 0xFF/*STREAM_REG*/, 0x00 /* ... */ };
     while (1) 
     {
         // transfer data from pc to gps
-        int o; 
-        char out[256] = { 0xFF, 0x00 /* ... */ };
-        for (o = 1; (o < sizeof(out)) && pc.readable(); ) 
+        if (pc.readable() && (o < sizeof(out)))
             out[o++] = pc.getc();
-        if (o > 1)
-        {
-            if (0 == gps.write(GPSADR,out,o))
-                /*ok*/;
-        }
+        if (pc.writeable() && i < s) 
+            pc.putc(in[i++]);
     
-        const char r = 0xFD; 
-        unsigned char sz[2];
-        int s = 0, i;
-        char in[1024];
-        if ( (0 == gps.write(GPSADR,&r,1, true)) &&
-             (0 == gps.read(GPSADR,(char*)sz,2,true)) )
+        if (tmr.read_ms() > 50)
         {
-            s = 256 * (int)sz[0] + sz[1];
-            if (s > sizeof(in)) 
-                s = sizeof(in);
-            if (s > 0) 
+            const char r = 0xFD /*LENGTH_REG*/; 
+            unsigned char sz[2];
+            if (0 == gps.write(GPSADR,&r,sizeof(r), true))
             {
-                 if (0 != gps.read(GPSADR,in,s,true))
-                    s = 0;
+                if (0 == gps.read(GPSADR,(char*)sz,sizeof(sz),true))
+                {
+                    int b  = (int)sz[0];
+                    b *= 256;
+                    b += sz[1];
+                    if (i == s)
+                        i = s = 0;
+                    if (b > sizeof(in)-s) 
+                        b = sizeof(in)-s;
+                    if (b > 0) 
+                    {
+                        if (0 == gps.read(GPSADR,&in[s],b,true))
+                            s += b;
+                    }
+                }
             }
-        }
-        gps.stop();
-    
-        for (i = 0; i < s; i ++)
-        {
-            while (!pc.writeable()) 
-                /*wait*/;
-            pc.putc(in[i]);
+            gps.stop();
+            if (o > 1)
+            {
+                if (0 == gps.write(GPSADR,out,o))
+                    o = 0;
+            }
+            tmr.reset();
         }
     }
 }