Serial passthrough with echo back to PC added - used for testing Emic 2 commands

Dependencies:   mbed

Committer:
4180_1
Date:
Thu Nov 26 01:48:35 2015 +0000
Revision:
0:4c2a5ae75108
ver 1.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
4180_1 0:4c2a5ae75108 1 #include "mbed.h"
4180_1 0:4c2a5ae75108 2
4180_1 0:4c2a5ae75108 3 RawSerial pc(USBTX, USBRX);
4180_1 0:4c2a5ae75108 4 RawSerial dev(p13,p14);
4180_1 0:4c2a5ae75108 5 DigitalOut led1(LED1);
4180_1 0:4c2a5ae75108 6 DigitalOut led4(LED4);
4180_1 0:4c2a5ae75108 7
4180_1 0:4c2a5ae75108 8 void dev_recv()
4180_1 0:4c2a5ae75108 9 {
4180_1 0:4c2a5ae75108 10 led1 = !led1;
4180_1 0:4c2a5ae75108 11 while(dev.readable()) {
4180_1 0:4c2a5ae75108 12 pc.putc(dev.getc());
4180_1 0:4c2a5ae75108 13 }
4180_1 0:4c2a5ae75108 14 }
4180_1 0:4c2a5ae75108 15
4180_1 0:4c2a5ae75108 16 void pc_recv()
4180_1 0:4c2a5ae75108 17 {
4180_1 0:4c2a5ae75108 18 led4 = !led4;
4180_1 0:4c2a5ae75108 19 char x;
4180_1 0:4c2a5ae75108 20 while(pc.readable()) {
4180_1 0:4c2a5ae75108 21 x=pc.getc();
4180_1 0:4c2a5ae75108 22 dev.putc(x);
4180_1 0:4c2a5ae75108 23 pc.putc(x); //echo back so that you can see what you are typing!
4180_1 0:4c2a5ae75108 24 }
4180_1 0:4c2a5ae75108 25 }
4180_1 0:4c2a5ae75108 26
4180_1 0:4c2a5ae75108 27 int main()
4180_1 0:4c2a5ae75108 28 {
4180_1 0:4c2a5ae75108 29 pc.baud(9600);
4180_1 0:4c2a5ae75108 30 dev.baud(9600);
4180_1 0:4c2a5ae75108 31
4180_1 0:4c2a5ae75108 32 pc.attach(&pc_recv, Serial::RxIrq);
4180_1 0:4c2a5ae75108 33 dev.attach(&dev_recv, Serial::RxIrq);
4180_1 0:4c2a5ae75108 34
4180_1 0:4c2a5ae75108 35 while(1) {
4180_1 0:4c2a5ae75108 36 sleep();
4180_1 0:4c2a5ae75108 37 }
4180_1 0:4c2a5ae75108 38 }