Example program for the SeeedStudio XBee Shield V2.0, based on UART serial port connectivity (D0/D1 pins). This program sends "HelloWorld" and prints out the received packets
main.cpp@3:3722ae2e3c20, 2015-02-13 (annotated)
- Committer:
- screamer
- Date:
- Fri Feb 13 09:38:52 2015 +0000
- Revision:
- 3:3722ae2e3c20
- Parent:
- 2:c487059c640d
Update mbed library.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
screamer | 2:c487059c640d | 1 | /* Copyright (c) 2010-2011 mbed.org, MIT License |
screamer | 2:c487059c640d | 2 | * |
screamer | 2:c487059c640d | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
screamer | 2:c487059c640d | 4 | * and associated documentation files (the "Software"), to deal in the Software without |
screamer | 2:c487059c640d | 5 | * restriction, including without limitation the rights to use, copy, modify, merge, publish, |
screamer | 2:c487059c640d | 6 | * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the |
screamer | 2:c487059c640d | 7 | * Software is furnished to do so, subject to the following conditions: |
screamer | 2:c487059c640d | 8 | * |
screamer | 2:c487059c640d | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
screamer | 2:c487059c640d | 10 | * substantial portions of the Software. |
screamer | 2:c487059c640d | 11 | * |
screamer | 2:c487059c640d | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
screamer | 2:c487059c640d | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
screamer | 2:c487059c640d | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
screamer | 2:c487059c640d | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
screamer | 2:c487059c640d | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
screamer | 2:c487059c640d | 17 | */ |
screamer | 2:c487059c640d | 18 | |
screamer | 0:78c3c0dabeb7 | 19 | #include "mbed.h" |
screamer | 0:78c3c0dabeb7 | 20 | #include "xbee.h" |
screamer | 0:78c3c0dabeb7 | 21 | |
screamer | 0:78c3c0dabeb7 | 22 | /** On many platforms USBTX/USBRX overlap with serial on D1/D0 pins and enabling the below will interrupt the communication. |
screamer | 0:78c3c0dabeb7 | 23 | * You can use an LCD display to print the values or store them on an SD card etc. |
screamer | 0:78c3c0dabeb7 | 24 | */ |
screamer | 0:78c3c0dabeb7 | 25 | //Serial pc(USBTX, USBRX); |
screamer | 0:78c3c0dabeb7 | 26 | |
screamer | 0:78c3c0dabeb7 | 27 | /** |
screamer | 1:f84c0ec86edf | 28 | * D1 - TX pin (RX on the shield side) |
screamer | 1:f84c0ec86edf | 29 | * D0 - RX pin (TX on the shield side) |
screamer | 0:78c3c0dabeb7 | 30 | * NC - Reset pin; use D5 otherwise the shield might get into reset loop |
screamer | 0:78c3c0dabeb7 | 31 | */ |
screamer | 0:78c3c0dabeb7 | 32 | xbee xb(D1, D0, D5); |
screamer | 0:78c3c0dabeb7 | 33 | |
screamer | 0:78c3c0dabeb7 | 34 | int main() |
screamer | 0:78c3c0dabeb7 | 35 | { |
screamer | 0:78c3c0dabeb7 | 36 | char data[202]; |
screamer | 0:78c3c0dabeb7 | 37 | |
screamer | 0:78c3c0dabeb7 | 38 | while(1) { |
screamer | 0:78c3c0dabeb7 | 39 | xb.SendData("HellWorld"); // Send "HelloWorld" |
screamer | 1:f84c0ec86edf | 40 | xb.RecieveData(data, 0); // Read data |
screamer | 0:78c3c0dabeb7 | 41 | printf("Received:%s", data); |
screamer | 0:78c3c0dabeb7 | 42 | wait(1); |
screamer | 0:78c3c0dabeb7 | 43 | } |
screamer | 0:78c3c0dabeb7 | 44 | } |