MAX3100, an external serial device to add additional serial ports via SPI
Dependents: FLIGHT_CONTROL_AND_COMMUNICATIONS_SYSTEM
example2.h
00001 /* 00002 Copyright (c) 2011 Andy Kirkham 00003 00004 Permission is hereby granted, free of charge, to any person obtaining a copy 00005 of this software and associated documentation files (the "Software"), to deal 00006 in the Software without restriction, including without limitation the rights 00007 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00008 copies of the Software, and to permit persons to whom the Software is 00009 furnished to do so, subject to the following conditions: 00010 00011 The above copyright notice and this permission notice shall be included in 00012 all copies or substantial portions of the Software. 00013 00014 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00015 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00016 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00017 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00018 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00019 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00020 THE SOFTWARE. 00021 */ 00022 00023 #ifdef MAX3100_EXAMPLE_COMPILE 00024 00025 /* 00026 * Connecting up the MAX3100 for this test program. Note, to form a "loopback" 00027 * the MAX3100 TX pin (13) is connected to the RX pin (12). Don't forget thwe Xtal 00028 * and power pins that are not shown here. Although I do PullUp mode on the IRQ pin 00029 * I still needed a real external pull up resistor on the IRQ lines. You may need to 00030 * add two pullups to teh two interrupt lines at p9 and p11. 00031 * ____________ 00032 * / \ U1 00033 * Mbed MOSI p5 |-------*---------------> 1| Din TX | 13 ------\ 00034 * MISO p6 |-----*-|---------------> 2| Dout | | 00035 * SCLK p7 |---*-|-|---------------> 3| Sclk RX | 12 ------/ 00036 * p8 |---|-|-|---------------> 4| CS | 00037 * p9 |---|-|-|---------------> 5| IRQ | MAX3100 00038 * | | | +5v ---> 6| SHTD | Xtal and PWR not shown. 00039 * | | | \____________/ 00040 * | | | ____________ 00041 * | | | / \ U2 00042 * | | \---------------> 1| Din TX | 13 ------\ 00043 * | \-----------------> 2| Dout | | 00044 * \-------------------> 3| Sclk RX | 12 ------/ 00045 * p10 |-----------------------> 4| CS | 00046 * p11 |-----------------------> 5| IRQ | MAX3100 00047 * +5v ---> 6| SHTD | Xtal and PWR not shown. 00048 * \____________/ 00049 * 00050 * This example shows two MAX3100 sharing a single SPI bus. Each device, however, 00051 * still has it's own CS and IRQ signals. 00052 */ 00053 00054 #include "mbed.h" 00055 #include "MAX3100.h" 00056 00057 Serial pc(USBTX, USBRX); 00058 SPI spi(p5, p6, p7); 00059 MAX3100 *max1; 00060 MAX3100 *max2; 00061 00062 int main() { 00063 00064 // Set the PC USB serial baud rate. 00065 pc.baud(115200); 00066 00067 // Format the SPI interface. 00068 spi.format(16, 0); 00069 spi.frequency(MAX3100_SPI_FREQ); 00070 00071 // Create the two MAX3100 objects which share the SPI bus. 00072 max1 = new MAX3100(&spi, p8, p9); 00073 max2 = new MAX3100(&spi, p10, p11); 00074 00075 // Enable the interrupts. 00076 max1->enableRxIrq(); 00077 max1->enableTxIrq(); 00078 max2->enableRxIrq(); 00079 max2->enableTxIrq(); 00080 00081 max1->printf("\nHello World.\n"); 00082 //max2->printf("\nHello World.\n"); 00083 00084 // Any byte received on the "USB serial port" is sent to both MAX3100 devices. 00085 // Any byte received by a MAX3100 device is sent to the "USB serial port". 00086 while (1) { 00087 if (pc.readable()) { 00088 int c = pc.getc(); 00089 max1->putc(c); 00090 max2->putc(c); 00091 } 00092 if (max1->readable()) { 00093 pc.putc( max1->getc() ); 00094 } 00095 if (max2->readable()) { 00096 pc.putc( max2->getc() ); 00097 } 00098 } 00099 } 00100 00101 #endif
Generated on Wed Jul 13 2022 13:30:40 by 1.7.2