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.
9 years, 10 months ago.
xbee transmitter and receiver
i'm testing a simple Xbee wireless communication, while the receiver can only receive the data in the first second, and it will not receive any data any more after that, can anybody check my code.
transmitter
#include "mbed.h" #include "C12832.h" C12832 lcd(p5, p7, p6, p8, p11); Serial pc(USBTX, USBRX); Serial xbee1(p9,p10); DigitalOut rst1(p30); //Digital reset for the XBee, 200ns for reset DigitalOut myled(LED3);//Create variable for Led 3 on the mbed int main() { rst1 = 0; //Set reset pin to 0 myled = 0;//Set LED3 to 0 wait_ms(1);//Wait at least one millisecond rst1 = 1;//Set reset pin to 1 wait_ms(1);//Wait another millisecond while (1) {//Neverending Loop myled = 1; //Turn Led 3 Off float a; a=10.655; xbee1.printf("%f",a); //XBee write whatever the PC is sending // xbee1.putc(b); wait(0.5); myled = 0; //Turn Led 3 on for succcessfull communication wait(0.5); lcd.cls(); lcd.locate(0,3); lcd.printf("%f",a); } }
receiver
#include "mbed.h" #include "C12832.h" C12832 lcd(p5, p7, p6, p8, p11); Serial xbee(p9, p10); Serial pc(USBTX, USBRX); DigitalOut rst1(p30); DigitalOut myled2(LED2); int main() { rst1 = 0; //Set reset pin to 0 myled2=0; wait_ms(1); rst1 = 1; //Set reset pin to 1 wait_ms(1); float X; while (1) { if(xbee.readable()){ xbee.scanf("%f", &X); // X = xbee.getc(); // wait(1); myled2 = 1; wait(0.5); myled2 = 0; wait(0.5); lcd.cls(); lcd.locate(0,3); lcd.printf("%f",X); } } }
2 Answers
9 years, 10 months ago.
Still no good, check the 'Editing tips' to add your code to the questions.
However, using Xbee as a receiver, code needs to be implemented on an 'interrupt' serial basis with your program checking the responses otherwise the data will be sent but the receiver may well 'miss' the transmission. Ideally both transmitter and receiver should be using interrupt serial with some form of handshaking.
9 years, 10 months ago.
The following related question might help: http://developer.mbed.org/questions/6745/How-to-use-an-Interrupt-ISR-for-receivin/
Could you please wrap your code in << code >><</ code >> (without the spaces between the word and the brackets)? I'm not sure what is a comment and what is code
posted by Brian Daniels 18 Mar 2015oh sry about that, i will show you the image, thanks for your reply!
posted by qi mao 18 Mar 2015