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

Dependents:   FLIGHT_CONTROL_AND_COMMUNICATIONS_SYSTEM

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers example1.h Source File

example1.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 line. You may need one
00030  * also.
00031  *                                    ____________
00032  *                                   /            \
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 
00042 #include "mbed.h"
00043 #include "MAX3100.h"
00044 
00045 Serial  pc(USBTX, USBRX);
00046 MAX3100 max(p5, p6, p7, p8, p9);
00047 
00048 int main() {
00049     
00050     // Set the PC USB serial baud rate.
00051     pc.baud(115200);
00052     
00053     max.enableRxIrq();
00054     max.enableTxIrq();
00055     
00056     max.printf("\nHello World.\n");
00057     
00058     // Any byte received on the "USB serial port" is sent to the MAX3100 device.
00059     // Any byte received by the MAX3100 device is sent to the "USB serial port".
00060     while (1) {
00061         if (pc.readable()) {
00062             int c = pc.getc();
00063             max.putc(c);            
00064         }
00065         if (max.readable()) {
00066             pc.putc( max.getc() );
00067         }
00068     }    
00069 }
00070 
00071 #endif