read write test for UART/RS232, debug via USB
Dependencies: mbed
Fork of DataLoggerRS232trial by
main.cpp@1:875d121e9ce9, 2016-09-14 (annotated)
- 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?
User | Revision | Line number | New 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 | 1:875d121e9ce9 | 5 | DataLoggerRS232 dataLogger (PA_2,PA_3); // tx, rx |
terrytamyh | 0:87fb6735eb09 | 6 | |
terrytamyh | 0:87fb6735eb09 | 7 | char DLcommand; |
Dengjj | 1:875d121e9ce9 | 8 | char DLcommand2; |
terrytamyh | 0:87fb6735eb09 | 9 | int main() { |
terrytamyh | 0:87fb6735eb09 | 10 | |
terrytamyh | 0:87fb6735eb09 | 11 | pc.baud(115200); |
terrytamyh | 0:87fb6735eb09 | 12 | pc.printf("PC and Datalogger serial set up complete !!\n\r"); |
Dengjj | 1:875d121e9ce9 | 13 | dataLogger.baud(9600); |
terrytamyh | 0:87fb6735eb09 | 14 | pc.printf("Here !!\n\r"); |
terrytamyh | 0:87fb6735eb09 | 15 | |
terrytamyh | 0:87fb6735eb09 | 16 | while(1) { |
terrytamyh | 0:87fb6735eb09 | 17 | if(pc.readable()) { |
terrytamyh | 0:87fb6735eb09 | 18 | |
terrytamyh | 0:87fb6735eb09 | 19 | dataLogger.count = 0; |
terrytamyh | 0:87fb6735eb09 | 20 | DLcommand = pc.getc(); |
terrytamyh | 0:87fb6735eb09 | 21 | pc.printf("\n\r%c\n\r",DLcommand); |
terrytamyh | 0:87fb6735eb09 | 22 | |
terrytamyh | 0:87fb6735eb09 | 23 | dataLogger.putc(DLcommand); |
terrytamyh | 0:87fb6735eb09 | 24 | dataLogger.get_ECU_databyte(); |
terrytamyh | 0:87fb6735eb09 | 25 | } |
Dengjj | 1:875d121e9ce9 | 26 | //dataLogger.display_ECU_databyte(); |
Dengjj | 1:875d121e9ce9 | 27 | wait(2); |
Dengjj | 1:875d121e9ce9 | 28 | //----------------------------------------------- |
Dengjj | 1:875d121e9ce9 | 29 | if(dataLogger.readable()) { |
Dengjj | 1:875d121e9ce9 | 30 | |
Dengjj | 1:875d121e9ce9 | 31 | dataLogger.count = 0; |
Dengjj | 1:875d121e9ce9 | 32 | DLcommand = dataLogger.getc(); |
Dengjj | 1:875d121e9ce9 | 33 | DLcommand2 = dataLogger.getc(); |
Dengjj | 1:875d121e9ce9 | 34 | pc.printf("\n\r%c\n\r",DLcommand); |
Dengjj | 1:875d121e9ce9 | 35 | pc.printf("\n\r%c\n\r",DLcommand2); |
Dengjj | 1:875d121e9ce9 | 36 | dataLogger.putc(DLcommand); |
Dengjj | 1:875d121e9ce9 | 37 | dataLogger.get_ECU_databyte(); |
Dengjj | 1:875d121e9ce9 | 38 | } |
Dengjj | 1:875d121e9ce9 | 39 | dataLogger.display_ECU_databyte(); |
Dengjj | 1:875d121e9ce9 | 40 | |
Dengjj | 1:875d121e9ce9 | 41 | wait(2); |
Dengjj | 1:875d121e9ce9 | 42 | |
terrytamyh | 0:87fb6735eb09 | 43 | } |
terrytamyh | 0:87fb6735eb09 | 44 | } |