Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp@1:f4f412b898f9, 2015-11-19 (annotated)
- Committer:
- joeharrison
- Date:
- Thu Nov 19 19:54:45 2015 +0000
- Revision:
- 1:f4f412b898f9
- Parent:
- 0:19219656fbf3
Busy loop instead
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| joeharrison | 0:19219656fbf3 | 1 | #include "mbed.h" |
| joeharrison | 0:19219656fbf3 | 2 | #include "C12832.h" |
| joeharrison | 0:19219656fbf3 | 3 | |
| joeharrison | 0:19219656fbf3 | 4 | // |
| joeharrison | 0:19219656fbf3 | 5 | // The Shed's "FTDI" |
| joeharrison | 0:19219656fbf3 | 6 | // 50 GBP of hardware to emulate 10 GBP of hardware because Joe likes to live wire |
| joeharrison | 0:19219656fbf3 | 7 | // |
| joeharrison | 0:19219656fbf3 | 8 | // SW2, SW3, FIRE will reset the XBee |
| joeharrison | 0:19219656fbf3 | 9 | // |
| joeharrison | 0:19219656fbf3 | 10 | |
| joeharrison | 0:19219656fbf3 | 11 | // Serial Devices |
| joeharrison | 0:19219656fbf3 | 12 | Serial pc(USBTX, USBRX); // tx, rx |
| joeharrison | 0:19219656fbf3 | 13 | Serial dev(D1, D0); // tx, rx |
| joeharrison | 0:19219656fbf3 | 14 | |
| joeharrison | 0:19219656fbf3 | 15 | // Interrupts for XBee reset |
| joeharrison | 0:19219656fbf3 | 16 | InterruptIn sw2_int(PTC6); |
| joeharrison | 0:19219656fbf3 | 17 | InterruptIn sw3_int(PTA4); |
| joeharrison | 0:19219656fbf3 | 18 | InterruptIn fire_int(D5); |
| joeharrison | 0:19219656fbf3 | 19 | |
| joeharrison | 0:19219656fbf3 | 20 | // XBee reset pin |
| joeharrison | 0:19219656fbf3 | 21 | DigitalOut rst(D3); |
| joeharrison | 0:19219656fbf3 | 22 | |
| joeharrison | 0:19219656fbf3 | 23 | // Print instructions on LCD |
| joeharrison | 0:19219656fbf3 | 24 | C12832 lcd(D11, D13, D12, D7, D10); |
| joeharrison | 0:19219656fbf3 | 25 | |
| joeharrison | 0:19219656fbf3 | 26 | void reset_xbee() { |
| joeharrison | 0:19219656fbf3 | 27 | rst = 0; |
| joeharrison | 0:19219656fbf3 | 28 | wait(0.5); |
| joeharrison | 0:19219656fbf3 | 29 | rst = 1; |
| joeharrison | 0:19219656fbf3 | 30 | } |
| joeharrison | 0:19219656fbf3 | 31 | |
| joeharrison | 0:19219656fbf3 | 32 | int main() { |
| joeharrison | 0:19219656fbf3 | 33 | |
| joeharrison | 0:19219656fbf3 | 34 | // Bring the reset pin to high |
| joeharrison | 0:19219656fbf3 | 35 | rst = 1; |
| joeharrison | 0:19219656fbf3 | 36 | |
| joeharrison | 0:19219656fbf3 | 37 | // Identify ourselves on the LCD |
| joeharrison | 0:19219656fbf3 | 38 | lcd.printf(" -- The Shed's \"FTDI\" -- \n"); |
| joeharrison | 0:19219656fbf3 | 39 | lcd.printf("50GBP to emulate 5GBP\n"); |
| joeharrison | 0:19219656fbf3 | 40 | lcd.printf("SW2/SW3/FIRE to RST XBee\n"); |
| joeharrison | 0:19219656fbf3 | 41 | |
| joeharrison | 0:19219656fbf3 | 42 | |
| joeharrison | 0:19219656fbf3 | 43 | // Switch setup |
| joeharrison | 0:19219656fbf3 | 44 | sw2_int.mode(PullUp); |
| joeharrison | 0:19219656fbf3 | 45 | sw2_int.fall(&reset_xbee); |
| joeharrison | 0:19219656fbf3 | 46 | |
| joeharrison | 0:19219656fbf3 | 47 | sw3_int.mode(PullUp); |
| joeharrison | 0:19219656fbf3 | 48 | sw3_int.fall(&reset_xbee); |
| joeharrison | 0:19219656fbf3 | 49 | |
| joeharrison | 0:19219656fbf3 | 50 | fire_int.mode(PullUp); |
| joeharrison | 0:19219656fbf3 | 51 | fire_int.fall(&reset_xbee); |
| joeharrison | 0:19219656fbf3 | 52 | |
| joeharrison | 0:19219656fbf3 | 53 | // PC serial |
| joeharrison | 0:19219656fbf3 | 54 | pc.baud(9600); |
| joeharrison | 0:19219656fbf3 | 55 | |
| joeharrison | 0:19219656fbf3 | 56 | // Device serial |
| joeharrison | 0:19219656fbf3 | 57 | dev.baud(9600); // XBee |
| joeharrison | 0:19219656fbf3 | 58 | |
| joeharrison | 0:19219656fbf3 | 59 | // Loop forever, allow for interrupts |
| joeharrison | 0:19219656fbf3 | 60 | while(1) { |
| joeharrison | 1:f4f412b898f9 | 61 | if (pc.readable()) { |
| joeharrison | 1:f4f412b898f9 | 62 | dev.putc(pc.getc()); |
| joeharrison | 1:f4f412b898f9 | 63 | } |
| joeharrison | 1:f4f412b898f9 | 64 | if (dev.readable()) { |
| joeharrison | 1:f4f412b898f9 | 65 | pc.putc(dev.getc()); |
| joeharrison | 1:f4f412b898f9 | 66 | } |
| joeharrison | 0:19219656fbf3 | 67 | } |
| joeharrison | 0:19219656fbf3 | 68 | |
| joeharrison | 0:19219656fbf3 | 69 | } |