A hacky bit of code to marshal serial data between a pc and xbee via an application shield. I am not proud of this, but I did fry the FTDI.

Dependencies:   C12832 mbed

Files at this revision

API Documentation at this revision

Comitter:
joeharrison
Date:
Thu Nov 19 19:54:45 2015 +0000
Parent:
0:19219656fbf3
Commit message:
Busy loop instead

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Thu Nov 19 18:52:56 2015 +0000
+++ b/main.cpp	Thu Nov 19 19:54:45 2015 +0000
@@ -22,18 +22,6 @@
 
 // Print instructions on LCD
 C12832 lcd(D11, D13, D12, D7, D10);
- 
-// Send everything from the PC's buffer to the XBee
-void send() {
-    while (pc.readable()) {
-        dev.putc(pc.getc());
-    }
-}
- 
-// Read a byte from the XBee to the PC
-void recv() {
-    pc.putc(dev.getc());
-}
 
 void reset_xbee() {
     rst = 0;
@@ -46,9 +34,6 @@
     // Bring the reset pin to high    
     rst = 1;
     
-    // Buffer for character from XBee
-    char c;
-    
     // Identify ourselves on the LCD
     lcd.printf(" -- The Shed's \"FTDI\" -- \n");
     lcd.printf("50GBP to emulate 5GBP\n");
@@ -67,15 +52,18 @@
     
     // PC serial     
     pc.baud(9600);
-    pc.attach(send, Serial::RxIrq);
     
     // Device serial 
     dev.baud(9600);   // XBee
  
     // Loop forever, allow for interrupts
     while(1) {
-        c = dev.getc();
-        pc.putc(c);
+        if (pc.readable()) {
+            dev.putc(pc.getc());
+        }
+        if (dev.readable()) {
+            pc.putc(dev.getc());
+        }
     }
  
 }
\ No newline at end of file