Harris Junaid
/
xbeeTOxbee
For xbee to xbee communication. The data entered on one terminal is appeared on other terminal.
main.cpp@1:63747acf15e4, 2012-04-27 (annotated)
- Committer:
- harrisjunaid
- Date:
- Fri Apr 27 00:59:25 2012 +0000
- Revision:
- 1:63747acf15e4
- Parent:
- 0:0787aeb09601
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
harrisjunaid | 0:0787aeb09601 | 1 | #include "mbed.h" |
harrisjunaid | 1:63747acf15e4 | 2 | #include "Serial.h" |
harrisjunaid | 1:63747acf15e4 | 3 | |
harrisjunaid | 1:63747acf15e4 | 4 | //XBEE Connection |
harrisjunaid | 0:0787aeb09601 | 5 | Serial xbee1(p9, p10);//XBEE (p3 DIN, p2 DOUT)<--> mbed (tx,rx) |
harrisjunaid | 1:63747acf15e4 | 6 | DigitalOut rst1(p8);//XBee pin 5 |
harrisjunaid | 1:63747acf15e4 | 7 | DigitalIn xbee_power(p11);//XBEE Power Indicator (XBee pin 13) |
harrisjunaid | 0:0787aeb09601 | 8 | DigitalOut xpower_LED(LED1);//XBEE Power LED <---> mbed LED1 |
harrisjunaid | 0:0787aeb09601 | 9 | DigitalIn xbee_associate(p12);//XBEE Association Digital In |
harrisjunaid | 0:0787aeb09601 | 10 | DigitalOut xassociate_LED(LED2);//XBEE Association LED <---> mbed LED2 |
harrisjunaid | 0:0787aeb09601 | 11 | |
harrisjunaid | 0:0787aeb09601 | 12 | |
harrisjunaid | 1:63747acf15e4 | 13 | |
harrisjunaid | 0:0787aeb09601 | 14 | |
harrisjunaid | 0:0787aeb09601 | 15 | //PC Serial |
harrisjunaid | 0:0787aeb09601 | 16 | Serial pc(USBTX, USBRX); |
harrisjunaid | 0:0787aeb09601 | 17 | |
harrisjunaid | 0:0787aeb09601 | 18 | int main() { |
harrisjunaid | 0:0787aeb09601 | 19 | |
harrisjunaid | 0:0787aeb09601 | 20 | // reset the xbees (at least 200ns) |
harrisjunaid | 1:63747acf15e4 | 21 | rst1 = 0; |
harrisjunaid | 0:0787aeb09601 | 22 | wait_ms(1); |
harrisjunaid | 1:63747acf15e4 | 23 | rst1 = 1; |
harrisjunaid | 0:0787aeb09601 | 24 | wait_ms(1); |
harrisjunaid | 0:0787aeb09601 | 25 | |
harrisjunaid | 0:0787aeb09601 | 26 | while(1) { |
harrisjunaid | 0:0787aeb09601 | 27 | if(xbee_power) //XBEE Power Check |
harrisjunaid | 0:0787aeb09601 | 28 | xpower_LED = 1; |
harrisjunaid | 0:0787aeb09601 | 29 | else |
harrisjunaid | 0:0787aeb09601 | 30 | xpower_LED = 0; |
harrisjunaid | 0:0787aeb09601 | 31 | |
harrisjunaid | 0:0787aeb09601 | 32 | if(xbee_associate)//XBEE Association Check |
harrisjunaid | 0:0787aeb09601 | 33 | xassociate_LED = 1; |
harrisjunaid | 0:0787aeb09601 | 34 | else |
harrisjunaid | 0:0787aeb09601 | 35 | xassociate_LED = 0; |
harrisjunaid | 0:0787aeb09601 | 36 | |
harrisjunaid | 0:0787aeb09601 | 37 | |
harrisjunaid | 0:0787aeb09601 | 38 | if(pc.readable()) {//User Entering Data |
harrisjunaid | 0:0787aeb09601 | 39 | xbee1.putc(pc.getc());//Transmit Data Entered By User (mbed tx <--> xbee DIN) |
harrisjunaid | 0:0787aeb09601 | 40 | // wait(0.03); |
harrisjunaid | 0:0787aeb09601 | 41 | } |
harrisjunaid | 0:0787aeb09601 | 42 | if(xbee1.readable()) {//XBEE 2 Received Data (xbee DOUT <--> mbed rx) |
harrisjunaid | 0:0787aeb09601 | 43 | pc.putc(xbee1.getc());//Print Data Received |
harrisjunaid | 0:0787aeb09601 | 44 | // wait(0.03); |
harrisjunaid | 0:0787aeb09601 | 45 | } |
harrisjunaid | 0:0787aeb09601 | 46 | } |
harrisjunaid | 0:0787aeb09601 | 47 | } |