Eric Fossum
/
STN1110Terminal
This is a simple program that will pass communications from the STN1110 to the mBed USB port.
Revision 0:a940e05190bc, committed 2013-03-19
- Comitter:
- fossum_13
- Date:
- Tue Mar 19 20:10:45 2013 +0000
- Commit message:
- initial release
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Mar 19 20:10:45 2013 +0000 @@ -0,0 +1,61 @@ +#include "mbed.h" + +Serial STN(p28, p27); +Serial pc(USBTX, USBRX); + +long STNBAUD = 9600; +long PCBAUD = 38400; + +void flushSerialBuffer(Serial *port); + +int main() { + // Configure PC BAUD + pc.baud(PCBAUD); + + // Setup STN1110 UART + pc.printf("Configuring STN UART\r\n"); + STN.baud(STNBAUD); + + // Get to a prompt + bool prompt = false; + while(!prompt) { + // Attempt communication + pc.printf("STN not ready\r\n"); + STN.printf("\r"); + wait(1); + + // Did we get a prompt? + while (STN.readable()) { + if (STN.getc() == '>') { + prompt = true; + flushSerialBuffer(&STN); + } + } + } + + // Attempt BAUD rate change + STN.printf("ATZ\r"); + pc.printf("STN BAUD == %d\r\n", STNBAUD); + + // Start terminal communication + while(1) { + if(STN.readable()) { + char c = STN.getc(); + pc.putc(c); + if (c == '\r') + pc.putc('\n'); + } + if(pc.readable()) { + char c = pc.getc(); + STN.putc(c); + } + } +} + +// Clears the Serial port buffer so we can get to new messages +void flushSerialBuffer(Serial *port) { + while ((*port).readable()) { + (*port).getc(); + } + return; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Tue Mar 19 20:10:45 2013 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/5e5da4a5990b \ No newline at end of file