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@5:598a573e3ad3, 2013-11-21 (annotated)
- Committer:
- mazgch
- Date:
- Thu Nov 21 14:12:14 2013 +0000
- Revision:
- 5:598a573e3ad3
- Parent:
- 4:0e065a08144b
- Child:
- 6:5a8fd99e6a09
reduce load on i2c
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 | 5:598a573e3ad3 | 6 | Timer tmr; |
mazgch | 5:598a573e3ad3 | 7 | tmr.start(); |
mazgch | 1:0d32baf4a645 | 8 | C027 c027; |
mazgch | 1:0d32baf4a645 | 9 | c027.gpsPower(true); |
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 | } |