Used to create a USB -> Serial link between a PC and a serial device

Dependencies:   mbed

Connect your serial device to p28 (tx) and p27 (rx). Change the baud rate to match your device. The baud rate must be the same for Serial pc and Serial device.

Committer:
joe4465
Date:
Thu Sep 18 08:37:54 2014 +0000
Revision:
0:8e51213bffbc
Final version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
joe4465 0:8e51213bffbc 1 #include "mbed.h"
joe4465 0:8e51213bffbc 2
joe4465 0:8e51213bffbc 3 DigitalOut myled(LED1);
joe4465 0:8e51213bffbc 4
joe4465 0:8e51213bffbc 5 Serial pc(USBTX, USBRX); // tx, rx
joe4465 0:8e51213bffbc 6 Serial device(p28, p27); // tx, rx
joe4465 0:8e51213bffbc 7
joe4465 0:8e51213bffbc 8 int main() {
joe4465 0:8e51213bffbc 9
joe4465 0:8e51213bffbc 10 device.baud(115200);
joe4465 0:8e51213bffbc 11 pc.baud(115200);
joe4465 0:8e51213bffbc 12
joe4465 0:8e51213bffbc 13
joe4465 0:8e51213bffbc 14 while(1) {
joe4465 0:8e51213bffbc 15 if(pc.readable()) {
joe4465 0:8e51213bffbc 16 device.putc(pc.getc());
joe4465 0:8e51213bffbc 17 }
joe4465 0:8e51213bffbc 18 if(device.readable()) {
joe4465 0:8e51213bffbc 19 myled = !myled;
joe4465 0:8e51213bffbc 20 pc.putc(device.getc());
joe4465 0:8e51213bffbc 21 }
joe4465 0:8e51213bffbc 22 }
joe4465 0:8e51213bffbc 23 }