Eric Fossum / Mbed 2 deprecated STN1110Terminal

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 Serial STN(p28, p27);
00004 Serial pc(USBTX, USBRX);
00005 
00006 long STNBAUD = 9600;
00007 long PCBAUD = 38400;
00008 
00009 void flushSerialBuffer(Serial *port);
00010 
00011 int main() {
00012     // Configure PC BAUD
00013     pc.baud(PCBAUD);
00014     
00015     // Setup STN1110 UART
00016     pc.printf("Configuring STN UART\r\n");
00017     STN.baud(STNBAUD);
00018     
00019     // Get to a prompt
00020     bool prompt = false;
00021     while(!prompt) {
00022         // Attempt communication
00023         pc.printf("STN not ready\r\n");
00024         STN.printf("\r");
00025         wait(1);
00026     
00027         // Did we get a prompt?
00028         while (STN.readable()) {
00029             if (STN.getc() == '>') {
00030                 prompt = true;
00031                 flushSerialBuffer(&STN);
00032             }
00033         }
00034     }
00035   
00036     // Attempt BAUD rate change
00037     STN.printf("ATZ\r");
00038     pc.printf("STN BAUD == %d\r\n", STNBAUD);
00039     
00040     // Start terminal communication
00041     while(1) {
00042         if(STN.readable()) {
00043             char c = STN.getc();
00044             pc.putc(c);
00045             if (c == '\r')
00046                 pc.putc('\n');
00047         }
00048         if(pc.readable()) {
00049             char c = pc.getc();
00050             STN.putc(c);
00051         }
00052     }
00053 }
00054 
00055 // Clears the Serial port buffer so we can get to new messages
00056 void flushSerialBuffer(Serial *port) {
00057     while ((*port).readable()) {
00058         (*port).getc();
00059     }
00060     return;
00061 }