Code to go on the coordinator to receive serial strings with xbee.h

Dependencies:   C12832_lcd mbed xbee_lib

Committer:
dannellyz
Date:
Sun Feb 15 06:06:14 2015 +0000
Revision:
0:674e712235c3
round 1 serial comms.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dannellyz 0:674e712235c3 1 #include "mbed.h"
dannellyz 0:674e712235c3 2 #include "xbee.h" // Include for xbee code
dannellyz 0:674e712235c3 3 #include "C12832_lcd.h" // Include for LCD code
dannellyz 0:674e712235c3 4
dannellyz 0:674e712235c3 5 xbee xbee1(p9,p10,p30); //Initalise xbee_lib varName(rx,tx,reset)
dannellyz 0:674e712235c3 6 DigitalOut rst1(p30);
dannellyz 0:674e712235c3 7 Serial pc(USBTX, USBRX); //Initalise PC serial comms
dannellyz 0:674e712235c3 8 C12832_LCD lcd; //Initialize LCD Screen
dannellyz 0:674e712235c3 9
dannellyz 0:674e712235c3 10 //Code to send strings acsross xbee with xbee.h
dannellyz 0:674e712235c3 11 //Code should be on the End Device
dannellyz 0:674e712235c3 12 int main()
dannellyz 0:674e712235c3 13 {
dannellyz 0:674e712235c3 14 // reset the xbees (at least 200ns)
dannellyz 0:674e712235c3 15 rst1 = 0;
dannellyz 0:674e712235c3 16 wait_ms(1);
dannellyz 0:674e712235c3 17 rst1 = 1;
dannellyz 0:674e712235c3 18 wait_ms(1);
dannellyz 0:674e712235c3 19
dannellyz 0:674e712235c3 20 //Establish a variable to receive data from End Device
dannellyz 0:674e712235c3 21 //Max buffer is 202
dannellyz 0:674e712235c3 22 char receiveData[4];
dannellyz 0:674e712235c3 23
dannellyz 0:674e712235c3 24 //Setup LCD screen
dannellyz 0:674e712235c3 25 lcd.cls();
dannellyz 0:674e712235c3 26 lcd.locate(0,1);
dannellyz 0:674e712235c3 27
dannellyz 0:674e712235c3 28 while(1) {
dannellyz 0:674e712235c3 29 //Recieve data from Xbee
dannellyz 0:674e712235c3 30 //Second argument is how many characters to read
dannellyz 0:674e712235c3 31 //If zero it will read sizeof(firstArg)
dannellyz 0:674e712235c3 32 xbee1.RecieveData(receiveData,0);
dannellyz 0:674e712235c3 33
dannellyz 0:674e712235c3 34 //Echo Locally...
dannellyz 0:674e712235c3 35 pc.printf("Recieved: %s\n", receiveData);
dannellyz 0:674e712235c3 36 lcd.printf("Recieved %s \n", receiveData);
dannellyz 0:674e712235c3 37 }
dannellyz 0:674e712235c3 38 }