read write test for UART/RS232, debug via USB

Dependencies:   mbed

Fork of DataLoggerRS232trial by Terry Tam

Committer:
Dengjj
Date:
Wed Sep 14 10:32:49 2016 +0000
Revision:
1:875d121e9ce9
Parent:
0:87fb6735eb09
Child:
2:6ebf09171de9
serail port read/write test

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
terrytamyh 0:87fb6735eb09 5 DataLoggerRS232::DataLoggerRS232(PinName tx, PinName rx, const char* name) : Serial(tx, rx, name) {
terrytamyh 0:87fb6735eb09 6 printf("Here!! \r\n");
terrytamyh 0:87fb6735eb09 7 // set up ring buffer
terrytamyh 0:87fb6735eb09 8 ringBuffer = new char[65536];
terrytamyh 0:87fb6735eb09 9 // pointer to first sample
terrytamyh 0:87fb6735eb09 10 rHead = ringBuffer;
terrytamyh 0:87fb6735eb09 11 // pointer to indicate position in the Ring Buffer
terrytamyh 0:87fb6735eb09 12 rPos = ringBuffer;
terrytamyh 0:87fb6735eb09 13 // pointer to indicate display position in the Ring Buffer
terrytamyh 0:87fb6735eb09 14 rDisplay = ringBuffer;
terrytamyh 0:87fb6735eb09 15
terrytamyh 0:87fb6735eb09 16 printf("DataLogger_RS232 Ring Buffer setup complete!\r\n");
terrytamyh 0:87fb6735eb09 17 }
terrytamyh 0:87fb6735eb09 18
terrytamyh 0:87fb6735eb09 19 void DataLoggerRS232::get_ECU_databyte() {
terrytamyh 0:87fb6735eb09 20
terrytamyh 0:87fb6735eb09 21 while(Serial::readable()) {
terrytamyh 0:87fb6735eb09 22
terrytamyh 0:87fb6735eb09 23 MSserial = Serial::getc();
terrytamyh 0:87fb6735eb09 24 // save the sample into ring buffer
terrytamyh 0:87fb6735eb09 25 if( rPos == &ringBuffer[65535] )
terrytamyh 0:87fb6735eb09 26 rPos = ringBuffer;
terrytamyh 0:87fb6735eb09 27 else
terrytamyh 0:87fb6735eb09 28 rPos++;
terrytamyh 0:87fb6735eb09 29
terrytamyh 0:87fb6735eb09 30 *rPos = MSserial;
terrytamyh 0:87fb6735eb09 31
terrytamyh 0:87fb6735eb09 32 count++;
terrytamyh 0:87fb6735eb09 33 }
terrytamyh 0:87fb6735eb09 34 printf("get_ECU_databyte !!\r\n");
terrytamyh 0:87fb6735eb09 35 }
terrytamyh 0:87fb6735eb09 36
terrytamyh 0:87fb6735eb09 37 void DataLoggerRS232::display_ECU_databyte() {
terrytamyh 0:87fb6735eb09 38
terrytamyh 0:87fb6735eb09 39 while (rDisplay != rPos) {
terrytamyh 0:87fb6735eb09 40 printf("%d, %X\n\r",count,rDisplay);
terrytamyh 0:87fb6735eb09 41 if( rDisplay == &ringBuffer[65535] )
terrytamyh 0:87fb6735eb09 42 rDisplay = ringBuffer;
terrytamyh 0:87fb6735eb09 43 else
terrytamyh 0:87fb6735eb09 44 rDisplay++;
terrytamyh 0:87fb6735eb09 45 }
terrytamyh 0:87fb6735eb09 46 printf("display_ECU_databyte !!\r\n");
Dengjj 1:875d121e9ce9 47
Dengjj 1:875d121e9ce9 48
terrytamyh 0:87fb6735eb09 49 }
terrytamyh 0:87fb6735eb09 50
terrytamyh 0:87fb6735eb09 51
terrytamyh 0:87fb6735eb09 52 DataLoggerRS232::~DataLoggerRS232() {
terrytamyh 0:87fb6735eb09 53 }