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:   C027-REVB mbed

Fork of C027_GPSTransparentI2C by u-blox

Committer:
dixter1
Date:
Sun Dec 15 21:45:58 2013 +0000
Revision:
7:ed20b127a513
Parent:
6:aed089da6b6e
Update Library Only.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mazgch 0:7f124c0a351a 1 #include "mbed.h"
mazgch 1:0d32baf4a645 2 #include "C027.h"
mazgch 0:7f124c0a351a 3
mazgch 3:a985a125f9fa 4 int main()
mazgch 0:7f124c0a351a 5 {
mazgch 5:598a573e3ad3 6 Timer tmr;
mazgch 5:598a573e3ad3 7 tmr.start();
mazgch 1:0d32baf4a645 8 C027 c027;
dixter1 6:aed089da6b6e 9 c027.gpsPower(true,false);
mazgch 3:a985a125f9fa 10
mazgch 2:832530e30120 11 // open the gps i2c port
mazgch 2:832530e30120 12 I2C gps(GPSSDA, GPSSCL);
mazgch 5:598a573e3ad3 13 gps.frequency(100000);
mazgch 3:a985a125f9fa 14
mazgch 0:7f124c0a351a 15 // open the PC serial port and (use the same baudrate)
mazgch 0:7f124c0a351a 16 Serial pc(USBTX, USBRX);
mazgch 0:7f124c0a351a 17 pc.baud(GPSBAUD);
mazgch 5:598a573e3ad3 18
mazgch 5:598a573e3ad3 19 int s = 0;
mazgch 5:598a573e3ad3 20 int i = 0;
mazgch 5:598a573e3ad3 21 int o = 1;
mazgch 5:598a573e3ad3 22 char in[1024];
mazgch 5:598a573e3ad3 23 char out[1024] = { 0xFF/*STREAM_REG*/, 0x00 /* ... */ };
mazgch 3:a985a125f9fa 24 while (1)
mazgch 0:7f124c0a351a 25 {
mazgch 0:7f124c0a351a 26 // transfer data from pc to gps
mazgch 5:598a573e3ad3 27 if (pc.readable() && (o < sizeof(out)))
mazgch 4:0e065a08144b 28 out[o++] = pc.getc();
mazgch 5:598a573e3ad3 29 if (pc.writeable() && i < s)
mazgch 5:598a573e3ad3 30 pc.putc(in[i++]);
mazgch 4:0e065a08144b 31
mazgch 5:598a573e3ad3 32 if (tmr.read_ms() > 50)
mazgch 2:832530e30120 33 {
mazgch 5:598a573e3ad3 34 const char r = 0xFD /*LENGTH_REG*/;
mazgch 5:598a573e3ad3 35 unsigned char sz[2];
mazgch 5:598a573e3ad3 36 if (0 == gps.write(GPSADR,&r,sizeof(r), true))
mazgch 4:0e065a08144b 37 {
mazgch 5:598a573e3ad3 38 if (0 == gps.read(GPSADR,(char*)sz,sizeof(sz),true))
mazgch 5:598a573e3ad3 39 {
mazgch 5:598a573e3ad3 40 int b = (int)sz[0];
mazgch 5:598a573e3ad3 41 b *= 256;
mazgch 5:598a573e3ad3 42 b += sz[1];
mazgch 5:598a573e3ad3 43 if (i == s)
mazgch 5:598a573e3ad3 44 i = s = 0;
mazgch 5:598a573e3ad3 45 if (b > sizeof(in)-s)
mazgch 5:598a573e3ad3 46 b = sizeof(in)-s;
mazgch 5:598a573e3ad3 47 if (b > 0)
mazgch 5:598a573e3ad3 48 {
mazgch 5:598a573e3ad3 49 if (0 == gps.read(GPSADR,&in[s],b,true))
mazgch 5:598a573e3ad3 50 s += b;
mazgch 5:598a573e3ad3 51 }
mazgch 5:598a573e3ad3 52 }
mazgch 4:0e065a08144b 53 }
mazgch 5:598a573e3ad3 54 gps.stop();
mazgch 5:598a573e3ad3 55 if (o > 1)
mazgch 5:598a573e3ad3 56 {
mazgch 5:598a573e3ad3 57 if (0 == gps.write(GPSADR,out,o))
mazgch 5:598a573e3ad3 58 o = 0;
mazgch 5:598a573e3ad3 59 }
mazgch 5:598a573e3ad3 60 tmr.reset();
mazgch 4:0e065a08144b 61 }
mazgch 0:7f124c0a351a 62 }
mazgch 0:7f124c0a351a 63 }