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
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
main.cpp@4:0e065a08144b, 2013-11-06 (annotated)
- Committer:
- mazgch
- Date:
- Wed Nov 06 10:49:39 2013 +0000
- Revision:
- 4:0e065a08144b
- Parent:
- 3:a985a125f9fa
- Child:
- 5:598a573e3ad3
use latest C027 library
Who changed what in which revision?
User | Revision | Line number | New 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 | 1:0d32baf4a645 | 6 | C027 c027; |
mazgch | 1:0d32baf4a645 | 7 | c027.gpsPower(true); |
mazgch | 3:a985a125f9fa | 8 | |
mazgch | 2:832530e30120 | 9 | // open the gps i2c port |
mazgch | 2:832530e30120 | 10 | I2C gps(GPSSDA, GPSSCL); |
mazgch | 3:a985a125f9fa | 11 | |
mazgch | 0:7f124c0a351a | 12 | // open the PC serial port and (use the same baudrate) |
mazgch | 0:7f124c0a351a | 13 | Serial pc(USBTX, USBRX); |
mazgch | 0:7f124c0a351a | 14 | pc.baud(GPSBAUD); |
mazgch | 3:a985a125f9fa | 15 | |
mazgch | 3:a985a125f9fa | 16 | while (1) |
mazgch | 0:7f124c0a351a | 17 | { |
mazgch | 0:7f124c0a351a | 18 | // transfer data from pc to gps |
mazgch | 4:0e065a08144b | 19 | int o; |
mazgch | 4:0e065a08144b | 20 | char out[256] = { 0xFF, 0x00 /* ... */ }; |
mazgch | 4:0e065a08144b | 21 | for (o = 1; (o < sizeof(out)) && pc.readable(); ) |
mazgch | 4:0e065a08144b | 22 | out[o++] = pc.getc(); |
mazgch | 4:0e065a08144b | 23 | if (o > 1) |
mazgch | 4:0e065a08144b | 24 | { |
mazgch | 4:0e065a08144b | 25 | if (0 == gps.write(GPSADR,out,o)) |
mazgch | 4:0e065a08144b | 26 | /*ok*/; |
mazgch | 4:0e065a08144b | 27 | } |
mazgch | 4:0e065a08144b | 28 | |
mazgch | 4:0e065a08144b | 29 | const char r = 0xFD; |
mazgch | 4:0e065a08144b | 30 | unsigned char sz[2]; |
mazgch | 4:0e065a08144b | 31 | int s = 0, i; |
mazgch | 4:0e065a08144b | 32 | char in[1024]; |
mazgch | 4:0e065a08144b | 33 | if ( (0 == gps.write(GPSADR,&r,1, true)) && |
mazgch | 4:0e065a08144b | 34 | (0 == gps.read(GPSADR,(char*)sz,2,true)) ) |
mazgch | 2:832530e30120 | 35 | { |
mazgch | 4:0e065a08144b | 36 | s = 256 * (int)sz[0] + sz[1]; |
mazgch | 4:0e065a08144b | 37 | if (s > sizeof(in)) |
mazgch | 4:0e065a08144b | 38 | s = sizeof(in); |
mazgch | 4:0e065a08144b | 39 | if (s > 0) |
mazgch | 4:0e065a08144b | 40 | { |
mazgch | 4:0e065a08144b | 41 | if (0 != gps.read(GPSADR,in,s,true)) |
mazgch | 4:0e065a08144b | 42 | s = 0; |
mazgch | 4:0e065a08144b | 43 | } |
mazgch | 2:832530e30120 | 44 | } |
mazgch | 4:0e065a08144b | 45 | gps.stop(); |
mazgch | 4:0e065a08144b | 46 | |
mazgch | 4:0e065a08144b | 47 | for (i = 0; i < s; i ++) |
mazgch | 4:0e065a08144b | 48 | { |
mazgch | 4:0e065a08144b | 49 | while (!pc.writeable()) |
mazgch | 4:0e065a08144b | 50 | /*wait*/; |
mazgch | 4:0e065a08144b | 51 | pc.putc(in[i]); |
mazgch | 4:0e065a08144b | 52 | } |
mazgch | 0:7f124c0a351a | 53 | } |
mazgch | 0:7f124c0a351a | 54 | } |