read write test for UART/RS232, debug via USB

Dependencies:   mbed

Fork of DataLoggerRS232trial by Terry Tam

main.cpp

Committer:
Dengjj
Date:
2016-09-14
Revision:
1:875d121e9ce9
Parent:
0:87fb6735eb09
Child:
2:6ebf09171de9

File content as of revision 1:875d121e9ce9:

#include "mbed.h"
#include "DataLoggerRS232.h"
 
Serial pc (USBTX, USBRX); // tx, rx
DataLoggerRS232 dataLogger (PA_2,PA_3);  // tx, rx

char DLcommand;
char DLcommand2;
int main() {    

    pc.baud(115200);
    pc.printf("PC and Datalogger serial set up complete !!\n\r");
    dataLogger.baud(9600);
    pc.printf("Here !!\n\r");
    
    while(1) {
        if(pc.readable()) {
            
            dataLogger.count = 0;
            DLcommand = pc.getc();
            pc.printf("\n\r%c\n\r",DLcommand);
            
            dataLogger.putc(DLcommand);
            dataLogger.get_ECU_databyte();
        }
        //dataLogger.display_ECU_databyte(); 
        wait(2);
//-----------------------------------------------        
        if(dataLogger.readable()) {
            
            dataLogger.count = 0;
            DLcommand = dataLogger.getc();
            DLcommand2 = dataLogger.getc();
            pc.printf("\n\r%c\n\r",DLcommand);
            pc.printf("\n\r%c\n\r",DLcommand2);
            dataLogger.putc(DLcommand);
            dataLogger.get_ECU_databyte();
        }
        dataLogger.display_ECU_databyte(); 
        
        wait(2);
            
    }
}