Xbee Comm Test

Dependencies:   Servo mbed xbee_lib

Committer:
ricefireflighter
Date:
Mon Feb 17 16:57:59 2014 +0000
Revision:
0:d67473a71dc6
share

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ricefireflighter 0:d67473a71dc6 1 #include "mbed.h"
ricefireflighter 0:d67473a71dc6 2 #include "xbee.h"
ricefireflighter 0:d67473a71dc6 3 #include "Servo.h"
ricefireflighter 0:d67473a71dc6 4 #include "PwmOut.h"
ricefireflighter 0:d67473a71dc6 5
ricefireflighter 0:d67473a71dc6 6 class xbee xbee1(PTD3,PTD2); //Initalise xbee_lib (Need to check these pins)
ricefireflighter 0:d67473a71dc6 7 Serial pc(USBTX, USBRX); //Initalise PC serial comms
ricefireflighter 0:d67473a71dc6 8 DigitalOut myled(LED_GREEN);
ricefireflighter 0:d67473a71dc6 9
ricefireflighter 0:d67473a71dc6 10 int main()
ricefireflighter 0:d67473a71dc6 11 {
ricefireflighter 0:d67473a71dc6 12 //Configure xbee with PanID of 6969 and exit config mode. Vary LED status.
ricefireflighter 0:d67473a71dc6 13 myled = !myled;
ricefireflighter 0:d67473a71dc6 14 xbee1.ConfigMode();
ricefireflighter 0:d67473a71dc6 15 wait(1);
ricefireflighter 0:d67473a71dc6 16 xbee1.SetPanId(6969);
ricefireflighter 0:d67473a71dc6 17 myled = !myled;
ricefireflighter 0:d67473a71dc6 18 xbee1.ExitConfigMode();
ricefireflighter 0:d67473a71dc6 19
ricefireflighter 0:d67473a71dc6 20 char send_data[202]; //Xbee buffer size is 202 bytes
ricefireflighter 0:d67473a71dc6 21 char read_data[202]; //Xbee buffer size is 202 bytes
ricefireflighter 0:d67473a71dc6 22
ricefireflighter 0:d67473a71dc6 23 while(1){
ricefireflighter 0:d67473a71dc6 24
ricefireflighter 0:d67473a71dc6 25 xbee1.RecieveData(read_data,0);
ricefireflighter 0:d67473a71dc6 26 // Line above receives data from xbee to FRDM as a char using getc.
ricefireflighter 0:d67473a71dc6 27 // See function definition for more info.
ricefireflighter 0:d67473a71dc6 28
ricefireflighter 0:d67473a71dc6 29 // Transfer information in read.data character string to useful motor/servo info here.
ricefireflighter 0:d67473a71dc6 30
ricefireflighter 0:d67473a71dc6 31 wait(0.1);
ricefireflighter 0:d67473a71dc6 32 // Wait for some amount of time to allow for complete data to be sent/received
ricefireflighter 0:d67473a71dc6 33 }
ricefireflighter 0:d67473a71dc6 34 }
ricefireflighter 0:d67473a71dc6 35
ricefireflighter 0:d67473a71dc6 36