MAX3100, an external serial device to add additional serial ports via SPI

Dependents:   FLIGHT_CONTROL_AND_COMMUNICATIONS_SYSTEM

Revision:
0:055897ab699b
Child:
1:46c8c60e744a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/example1.h	Sun Jan 16 18:27:44 2011 +0000
@@ -0,0 +1,72 @@
+/*
+    Copyright (c) 2011 Andy Kirkham
+ 
+    Permission is hereby granted, free of charge, to any person obtaining a copy
+    of this software and associated documentation files (the "Software"), to deal
+    in the Software without restriction, including without limitation the rights
+    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+    copies of the Software, and to permit persons to whom the Software is
+    furnished to do so, subject to the following conditions:
+ 
+    The above copyright notice and this permission notice shall be included in
+    all copies or substantial portions of the Software.
+ 
+    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+    THE SOFTWARE.
+*/
+
+#ifdef MAX3100_EXAMPLE_COMPILE
+
+/*
+ * Connecting up the MAX3100 for this test program. Note, to form a "loopback"
+ * the MAX3100 TX pin (13) is connected to the RX pin (12). Don't forget thwe Xtal
+ * and power pins that are not shown here. Although I do PullUp mode on the IRQ pin
+ * I still needed a real external pull up resistor on the IRQ line. You may need one
+ * also.
+ *                                    ____________
+ *                                   /            \
+ * Mbed MOSI p5 |-----------------> 1| Din     TX | 13 ------\
+ *      MISO p6 |-----------------> 2| Dout       |          |
+ *      SCLK p7 |-----------------> 3| Sclk    RX | 12 ------/
+ *           p8 |-----------------> 4| CS         |
+ *           p9 |-----------------> 5| IRQ        | MAX3100
+ *                      +5v ------> 6| SHTD       | Xtal and PWR not shown.
+ *                                   \____________/
+ */
+
+#include "mbed.h"
+#include "MAX3100.h"
+
+Serial  pc(USBTX, USBRX);
+MAX3100 max(p5, p6, p7, p8, p9);
+
+int main() {
+    
+    // Set the PC USB serial baud rate.
+    pc.baud(115200);
+    
+    max.enableRxIrq();
+    max.enableTxIrq();
+    
+    max.printf("\nHello World.\n");
+    
+    // Any byte received on the "USB serial port" is sent to the MAX3100 device.
+    // Any byte received by the MAX3100 device is sent to the "USB serial port".
+    while (1) {
+        if (pc.readable()) {
+            int c = pc.getc();
+            while (!max.writable());
+            max.putc(c);            
+        }
+        if (max.readable()) {
+            pc.putc( max.getc() );
+        }
+    }    
+}
+
+#endif