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

Committer:
mazgch
Date:
Thu Jun 12 07:29:34 2014 +0000
Revision:
6:5a8fd99e6a09
Parent:
5:598a573e3ad3
update libraries (use api provided by the platform)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mazgch 0:7f124c0a351a 1 #include "mbed.h"
mazgch 6:5a8fd99e6a09 2 #ifdef TARGET_UBLOX_C027
mazgch 6:5a8fd99e6a09 3 #include "C027_api.h"
mazgch 6:5a8fd99e6a09 4 #else
mazgch 6:5a8fd99e6a09 5 #error "This example is targeted for the C027 platform"
mazgch 6:5a8fd99e6a09 6 #endif
mazgch 0:7f124c0a351a 7
mazgch 6:5a8fd99e6a09 8 /* This example is establishing a transparent link between
mazgch 6:5a8fd99e6a09 9 the mbed serial port and the I2C communication interface
mazgch 6:5a8fd99e6a09 10 of the GPS.
mazgch 6:5a8fd99e6a09 11
mazgch 6:5a8fd99e6a09 12 For a more advanced driver for the GPS or Modem(MDM) please
mazgch 6:5a8fd99e6a09 13 look at the follwing library and example:
mazgch 6:5a8fd99e6a09 14 C027_Support Library
mazgch 6:5a8fd99e6a09 15 http://mbed.org/teams/ublox/code/C027_Support/
mazgch 6:5a8fd99e6a09 16 C027_Support Example
mazgch 6:5a8fd99e6a09 17 http://mbed.org/teams/ublox/code/C027_SupportTest/
mazgch 6:5a8fd99e6a09 18 */
mazgch 3:a985a125f9fa 19 int main()
mazgch 0:7f124c0a351a 20 {
mazgch 5:598a573e3ad3 21 Timer tmr;
mazgch 5:598a573e3ad3 22 tmr.start();
mazgch 6:5a8fd99e6a09 23 c027_gps_powerOn();
mazgch 3:a985a125f9fa 24
mazgch 2:832530e30120 25 // open the gps i2c port
mazgch 2:832530e30120 26 I2C gps(GPSSDA, GPSSCL);
mazgch 5:598a573e3ad3 27 gps.frequency(100000);
mazgch 3:a985a125f9fa 28
mazgch 0:7f124c0a351a 29 // open the PC serial port and (use the same baudrate)
mazgch 0:7f124c0a351a 30 Serial pc(USBTX, USBRX);
mazgch 0:7f124c0a351a 31 pc.baud(GPSBAUD);
mazgch 5:598a573e3ad3 32
mazgch 5:598a573e3ad3 33 int s = 0;
mazgch 5:598a573e3ad3 34 int i = 0;
mazgch 5:598a573e3ad3 35 int o = 1;
mazgch 5:598a573e3ad3 36 char in[1024];
mazgch 5:598a573e3ad3 37 char out[1024] = { 0xFF/*STREAM_REG*/, 0x00 /* ... */ };
mazgch 3:a985a125f9fa 38 while (1)
mazgch 0:7f124c0a351a 39 {
mazgch 0:7f124c0a351a 40 // transfer data from pc to gps
mazgch 5:598a573e3ad3 41 if (pc.readable() && (o < sizeof(out)))
mazgch 4:0e065a08144b 42 out[o++] = pc.getc();
mazgch 5:598a573e3ad3 43 if (pc.writeable() && i < s)
mazgch 5:598a573e3ad3 44 pc.putc(in[i++]);
mazgch 4:0e065a08144b 45
mazgch 5:598a573e3ad3 46 if (tmr.read_ms() > 50)
mazgch 2:832530e30120 47 {
mazgch 5:598a573e3ad3 48 const char r = 0xFD /*LENGTH_REG*/;
mazgch 5:598a573e3ad3 49 unsigned char sz[2];
mazgch 5:598a573e3ad3 50 if (0 == gps.write(GPSADR,&r,sizeof(r), true))
mazgch 4:0e065a08144b 51 {
mazgch 5:598a573e3ad3 52 if (0 == gps.read(GPSADR,(char*)sz,sizeof(sz),true))
mazgch 5:598a573e3ad3 53 {
mazgch 5:598a573e3ad3 54 int b = (int)sz[0];
mazgch 5:598a573e3ad3 55 b *= 256;
mazgch 5:598a573e3ad3 56 b += sz[1];
mazgch 5:598a573e3ad3 57 if (i == s)
mazgch 5:598a573e3ad3 58 i = s = 0;
mazgch 5:598a573e3ad3 59 if (b > sizeof(in)-s)
mazgch 5:598a573e3ad3 60 b = sizeof(in)-s;
mazgch 5:598a573e3ad3 61 if (b > 0)
mazgch 5:598a573e3ad3 62 {
mazgch 5:598a573e3ad3 63 if (0 == gps.read(GPSADR,&in[s],b,true))
mazgch 5:598a573e3ad3 64 s += b;
mazgch 5:598a573e3ad3 65 }
mazgch 5:598a573e3ad3 66 }
mazgch 4:0e065a08144b 67 }
mazgch 5:598a573e3ad3 68 gps.stop();
mazgch 5:598a573e3ad3 69 if (o > 1)
mazgch 5:598a573e3ad3 70 {
mazgch 5:598a573e3ad3 71 if (0 == gps.write(GPSADR,out,o))
mazgch 5:598a573e3ad3 72 o = 0;
mazgch 5:598a573e3ad3 73 }
mazgch 5:598a573e3ad3 74 tmr.reset();
mazgch 4:0e065a08144b 75 }
mazgch 0:7f124c0a351a 76 }
mazgch 0:7f124c0a351a 77 }