XBee ZigBee communicator receives reports from other XBee modules from the Personal Network and writes it to the PC though the default Serial channel.

Dependencies:   mbed BufferedSerial

Committer:
cspista
Date:
Thu Dec 16 12:42:47 2021 +0000
Revision:
0:b130d24d6fa3
Final version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
cspista 0:b130d24d6fa3 1 #include "mbed.h"
cspista 0:b130d24d6fa3 2 #include "BufferedSerial.h"
cspista 0:b130d24d6fa3 3
cspista 0:b130d24d6fa3 4 BufferedSerial pc(USBTX,USBRX);
cspista 0:b130d24d6fa3 5 BufferedSerial xbee(PA_0, PA_1);
cspista 0:b130d24d6fa3 6
cspista 0:b130d24d6fa3 7 char fb[1024];
cspista 0:b130d24d6fa3 8
cspista 0:b130d24d6fa3 9 int main()
cspista 0:b130d24d6fa3 10 {
cspista 0:b130d24d6fa3 11 pc.baud(115200);
cspista 0:b130d24d6fa3 12 xbee.baud(38400);
cspista 0:b130d24d6fa3 13 int i = 0;
cspista 0:b130d24d6fa3 14 pc.printf("\r\nXbee COORDINATOR1 received:\r\n");
cspista 0:b130d24d6fa3 15 while(1) {
cspista 0:b130d24d6fa3 16 while(xbee.readable()) {
cspista 0:b130d24d6fa3 17 fb[i++] = xbee.getc();
cspista 0:b130d24d6fa3 18 }
cspista 0:b130d24d6fa3 19 if(i<20) {
cspista 0:b130d24d6fa3 20 wait(0.5);
cspista 0:b130d24d6fa3 21 } else {
cspista 0:b130d24d6fa3 22 for(int c=0; c<i; c++) {
cspista 0:b130d24d6fa3 23 pc.printf("%02x ",fb[c]);
cspista 0:b130d24d6fa3 24 }
cspista 0:b130d24d6fa3 25 pc.printf("\r\n");
cspista 0:b130d24d6fa3 26 i = 0;
cspista 0:b130d24d6fa3 27 }
cspista 0:b130d24d6fa3 28 }
cspista 0:b130d24d6fa3 29 }