read write test for UART/RS232, debug via USB

Dependencies:   mbed

Fork of DataLoggerRS232trial by Terry Tam

Committer:
Dengjj
Date:
Sun Sep 18 05:45:40 2016 +0000
Revision:
2:6ebf09171de9
Parent:
1:875d121e9ce9
read biao power summary

Who changed what in which revision?

UserRevisionLine numberNew contents of line
terrytamyh 0:87fb6735eb09 1 #include "mbed.h"
terrytamyh 0:87fb6735eb09 2 #include "DataLoggerRS232.h"
terrytamyh 0:87fb6735eb09 3
terrytamyh 0:87fb6735eb09 4 Serial pc (USBTX, USBRX); // tx, rx
Dengjj 2:6ebf09171de9 5 Serial dataLogger (PA_2,PA_3); // tx, rx
terrytamyh 0:87fb6735eb09 6
Dengjj 2:6ebf09171de9 7 //char DLcommand;
Dengjj 2:6ebf09171de9 8 int abc[]={104,87,36,19,0,0,0,104,17,4,51,51,51,51,63,22};
Dengjj 2:6ebf09171de9 9
Dengjj 1:875d121e9ce9 10 char DLcommand2;
terrytamyh 0:87fb6735eb09 11 int main() {
terrytamyh 0:87fb6735eb09 12
terrytamyh 0:87fb6735eb09 13 pc.baud(115200);
terrytamyh 0:87fb6735eb09 14 pc.printf("PC and Datalogger serial set up complete !!\n\r");
Dengjj 2:6ebf09171de9 15 dataLogger.baud(2400);
Dengjj 2:6ebf09171de9 16 dataLogger.format(9,SerialBase::Even,1);
terrytamyh 0:87fb6735eb09 17 pc.printf("Here !!\n\r");
Dengjj 2:6ebf09171de9 18 int i;
Dengjj 2:6ebf09171de9 19 const int m=16;
terrytamyh 0:87fb6735eb09 20 while(1) {
Dengjj 2:6ebf09171de9 21 i=0;
Dengjj 2:6ebf09171de9 22 // if(pc.readable()) {
Dengjj 2:6ebf09171de9 23 if(dataLogger.writeable()){
Dengjj 2:6ebf09171de9 24 for(i=0;i<m;i++){
Dengjj 2:6ebf09171de9 25 dataLogger.putc(abc[i]);
Dengjj 2:6ebf09171de9 26 }
Dengjj 2:6ebf09171de9 27 pc.printf("T");
Dengjj 2:6ebf09171de9 28 // dataLogger.printf("%c",DLcommand);
Dengjj 2:6ebf09171de9 29 // dataLogger.count = 0;
Dengjj 2:6ebf09171de9 30 // DLcommand = pc.getc();
Dengjj 2:6ebf09171de9 31 // pc.printf("\n\r%c\n\r",DLcommand);
terrytamyh 0:87fb6735eb09 32
Dengjj 2:6ebf09171de9 33 // dataLogger.putc(DLcommand);
Dengjj 2:6ebf09171de9 34 // dataLogger.get_ECU_databyte();
terrytamyh 0:87fb6735eb09 35 }
Dengjj 2:6ebf09171de9 36 // dataLogger.display_ECU_databyte();
Dengjj 2:6ebf09171de9 37 // wait(4);
Dengjj 1:875d121e9ce9 38 //-----------------------------------------------
Dengjj 2:6ebf09171de9 39 if(dataLogger.readable()) {
Dengjj 2:6ebf09171de9 40 pc.printf("R");
Dengjj 2:6ebf09171de9 41 char DLcommand[25];
Dengjj 2:6ebf09171de9 42 // dataLogger.count = 0;
Dengjj 2:6ebf09171de9 43 for(i=0;i<25;i++){
Dengjj 2:6ebf09171de9 44 DLcommand[i]= dataLogger.getc();
Dengjj 2:6ebf09171de9 45 pc.putc(DLcommand[i]);
Dengjj 2:6ebf09171de9 46 }
Dengjj 2:6ebf09171de9 47 // DLcommand = dataLogger.getc();
Dengjj 2:6ebf09171de9 48 // DLcommand2 = dataLogger.getc();
Dengjj 2:6ebf09171de9 49
Dengjj 2:6ebf09171de9 50 ;
Dengjj 2:6ebf09171de9 51 // pc.printf("\n\r%c\n\r",DLcommand2);
Dengjj 2:6ebf09171de9 52 // dataLogger.putc(DLcommand);
Dengjj 2:6ebf09171de9 53 // dataLogger.get_ECU_databyte();
Dengjj 2:6ebf09171de9 54 }
Dengjj 2:6ebf09171de9 55 // dataLogger.display_ECU_databyte();
Dengjj 2:6ebf09171de9 56
Dengjj 2:6ebf09171de9 57 wait(4);
Dengjj 1:875d121e9ce9 58
Dengjj 2:6ebf09171de9 59 }}