Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
12 years, 4 months ago.
Turn remote LED on/off + xbee
Hi guys, i am trying to send commands from the FRDM KL25Z board where i have attached a xbee coordinator in API mode to a remote Xbee router configured in AT mode in order to turn on/off a remote LED on pin DI/O 3. I don't know how to get response from the Xbee router so that i know that it actually works.The code i have written is this:
#include "mbed.h"
Serial pc(USBTX, USBRX); // tx, rx
Serial xbee(PTD3, PTD2); // tx, rx
DigitalOut myled(LED1);
DigitalOut mypins(PTD0);
int main()
{
int value;
pc.baud(9600);
xbee.baud(9600);
char mychar1;
char mychar2;
value= 0x05;
while (1) {
if (value == 0x05)
{ value = 0x04;
myled = 0;
}
else
{
value = 0x05;
myled = 1;
}
xbee.putc(0x7E); //start byte of API frame
xbee.putc(0x0); //high part of length.It always zero
xbee.putc(0x10); //low part of length.The number of bytes that follow,not including checksum
xbee.putc(0x17); // frame type.In this case 0x17 is a remote AT command
xbee.putc(0x0); //Frame ID.No acknowledgment is needed.The remote xbee will receive what we send
xbee.putc(0x0);
xbee.putc(0x0);
xbee.putc(0x0);
xbee.putc(0x0);
xbee.putc(0x0);
xbee.putc(0xFF); // 0xFF for broadcast
xbee.putc(0xFF); // 0xFF for broadcast
xbee.putc(0xFF); // Destination Network Adress. 16 bit of recipient or 0xFFFE
xbee.putc(0xFE); // Destination Network Adress 0xFE-broadcast
xbee.putc(0x02); // 0x02 to apply changes immediately or remote
xbee.putc('D'); // command name in ASCII characters
xbee.putc('3');
mychar1 = xbee.putc(value); // turn LED on/off.Command data in as many bytes as needed
pc.printf("%x",mychar1);
long sum = (0x17 + 0xFF + 0xFF + 0xFF + 0xFE + 0x02 + 'D' + '3' + value); //checksum is all bytes after length bytes
mychar2 = xbee.putc( 0xFF- sum & 0xFF); //calculate the proper checksum
pc.printf("%x",mychar2);
wait(5);
}
}