
This example establishes a transparent link between the mbed USB CDC port and the modem (LISA) on the C027. You can use it to use the standard u-blox tools such as m-center or any terminal program. These tools can then connect to the serial port and talk directly to the modem. Baudrate should be set to 115200 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/m-center.html
Dependencies: C027 UbloxUSBModem mbed
Fork of C027_ModemTransparentSerial 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
Revision 2:20ff91824a26, committed 2013-10-25
- Comitter:
- mazgch
- Date:
- Fri Oct 25 20:16:46 2013 +0000
- Parent:
- 1:7334dcb895d0
- Child:
- 3:8d37a7a064f1
- Commit message:
- version for USB CDC
Changed in this revision
UbloxUSBModem.lib | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/UbloxUSBModem.lib Fri Oct 25 20:16:46 2013 +0000 @@ -0,0 +1,1 @@ +https://mbed.org/users/mbed_official/code/UbloxUSBModem/#6e9d98f8c237
--- a/main.cpp Wed Oct 23 06:12:48 2013 +0000 +++ b/main.cpp Fri Oct 25 20:16:46 2013 +0000 @@ -1,26 +1,57 @@ #include "mbed.h" #include "C027_PinNames.h" +#include "WANDongle.h" +#include "USBSerialStream.h" +#include "UbloxCDMAModemInitializer.h" +#include "UbloxGSMModemInitializer.h" int main() { // open the mdm serial port - Serial mdm(MDMTXD, MDMRXD); - mdm.baud(MDMBAUD); - // tell the modem that we can always receive data - DigitalOut mdmRts(MDMRTS); - mdmRts = 0; // (not using flow control) - + WANDongle mdmDongle; + USBSerialStream mdmStream(mdmDongle.getSerial(0/* the CDC usually 0 or 1*/ )); + USBHost* host = USBHost::getHostInst(); + mdmDongle.addInitializer(new UbloxCDMAModemInitializer(host)); + mdmDongle.addInitializer(new UbloxGSMModemInitializer(host)); + // open the PC serial port and (use the same baudrate) Serial pc(USBTX, USBRX); pc.baud(MDMBAUD); while (1) { - // transfer data from pc to modem - if (pc.readable() && mdm.writeable()) - mdm.putc(pc.getc()); - // transfer data from modem to pc - if (mdm.readable() && pc.writeable()) - pc.putc(mdm.getc()); + uint8_t buf[64]; + size_t len; + int i; + if (!mdmDongle.connected()) + { + mdmDongle.tryConnect(); + } + else + { + // transfer data from pc to modem + len = mdmStream.space(); + if (len>0) + { + if (len > sizeof(buf)) + len = sizeof(buf); + for (i = 0; (i < len) && pc.readable(); ) + buf[i++] = pc.getc(); + if (OK == mdmStream.write(buf, i)) + /* what to do here ?*/; + } + // transfer data from modem to pc + len = mdmStream.available(); + if ((len>0) && pc.writeable()) + { + if (len > sizeof(buf)) + len = sizeof(buf); + if (OK == mdmStream.read(buf, &len, len)) + { + for (i = 0; (i < len); ) + pc.putc(buf[i++]); + } + } + } } }