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

Dependents:   FLIGHT_CONTROL_AND_COMMUNICATIONS_SYSTEM

Committer:
AjK
Date:
Fri Aug 03 12:28:27 2012 +0000
Revision:
2:2a49171453d5
Parent:
1:46c8c60e744a
Add example4.h and ISR user callback code

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AjK 0:055897ab699b 1 /*
AjK 0:055897ab699b 2 Copyright (c) 2011 Andy Kirkham
AjK 0:055897ab699b 3
AjK 0:055897ab699b 4 Permission is hereby granted, free of charge, to any person obtaining a copy
AjK 0:055897ab699b 5 of this software and associated documentation files (the "Software"), to deal
AjK 0:055897ab699b 6 in the Software without restriction, including without limitation the rights
AjK 0:055897ab699b 7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
AjK 0:055897ab699b 8 copies of the Software, and to permit persons to whom the Software is
AjK 0:055897ab699b 9 furnished to do so, subject to the following conditions:
AjK 0:055897ab699b 10
AjK 0:055897ab699b 11 The above copyright notice and this permission notice shall be included in
AjK 0:055897ab699b 12 all copies or substantial portions of the Software.
AjK 0:055897ab699b 13
AjK 0:055897ab699b 14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
AjK 0:055897ab699b 15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
AjK 0:055897ab699b 16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AjK 0:055897ab699b 17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
AjK 0:055897ab699b 18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
AjK 0:055897ab699b 19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
AjK 0:055897ab699b 20 THE SOFTWARE.
AjK 0:055897ab699b 21 */
AjK 0:055897ab699b 22
AjK 0:055897ab699b 23 #ifdef MAX3100_EXAMPLE_COMPILE
AjK 0:055897ab699b 24
AjK 0:055897ab699b 25 /*
AjK 0:055897ab699b 26 * Connecting up the MAX3100 for this test program. Note, to form a "loopback"
AjK 0:055897ab699b 27 * the MAX3100 TX pin (13) is connected to the RX pin (12). Don't forget thwe Xtal
AjK 0:055897ab699b 28 * and power pins that are not shown here. Although I do PullUp mode on the IRQ pin
AjK 0:055897ab699b 29 * I still needed a real external pull up resistor on the IRQ line. You may need one
AjK 0:055897ab699b 30 * also.
AjK 0:055897ab699b 31 * ____________
AjK 0:055897ab699b 32 * / \
AjK 0:055897ab699b 33 * Mbed MOSI p5 |-----------------> 1| Din TX | 13 ------\
AjK 0:055897ab699b 34 * MISO p6 |-----------------> 2| Dout | |
AjK 0:055897ab699b 35 * SCLK p7 |-----------------> 3| Sclk RX | 12 ------/
AjK 0:055897ab699b 36 * p8 |-----------------> 4| CS |
AjK 0:055897ab699b 37 * p9 |-----------------> 5| IRQ | MAX3100
AjK 0:055897ab699b 38 * +5v ------> 6| SHTD | Xtal and PWR not shown.
AjK 0:055897ab699b 39 * \____________/
AjK 0:055897ab699b 40 */
AjK 0:055897ab699b 41
AjK 0:055897ab699b 42 #include "mbed.h"
AjK 0:055897ab699b 43 #include "MAX3100.h"
AjK 0:055897ab699b 44
AjK 0:055897ab699b 45 Serial pc(USBTX, USBRX);
AjK 0:055897ab699b 46 MAX3100 max(p5, p6, p7, p8, p9);
AjK 0:055897ab699b 47
AjK 0:055897ab699b 48 int main() {
AjK 0:055897ab699b 49
AjK 0:055897ab699b 50 // Set the PC USB serial baud rate.
AjK 0:055897ab699b 51 pc.baud(115200);
AjK 0:055897ab699b 52
AjK 0:055897ab699b 53 max.enableRxIrq();
AjK 0:055897ab699b 54 max.enableTxIrq();
AjK 0:055897ab699b 55
AjK 0:055897ab699b 56 max.printf("\nHello World.\n");
AjK 0:055897ab699b 57
AjK 0:055897ab699b 58 // Any byte received on the "USB serial port" is sent to the MAX3100 device.
AjK 0:055897ab699b 59 // Any byte received by the MAX3100 device is sent to the "USB serial port".
AjK 0:055897ab699b 60 while (1) {
AjK 0:055897ab699b 61 if (pc.readable()) {
AjK 0:055897ab699b 62 int c = pc.getc();
AjK 0:055897ab699b 63 max.putc(c);
AjK 0:055897ab699b 64 }
AjK 0:055897ab699b 65 if (max.readable()) {
AjK 0:055897ab699b 66 pc.putc( max.getc() );
AjK 0:055897ab699b 67 }
AjK 0:055897ab699b 68 }
AjK 0:055897ab699b 69 }
AjK 0:055897ab699b 70
AjK 0:055897ab699b 71 #endif