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.
10 years ago.
"serial.readable()", "serial.getc()" and serial interrupt not working
Hello all :) I am trying to send a character serially from one LPC1768 to the other over RF 434MHz link and print them on the terminal of a PC. However when trying to send a character from one controller to other, the receiver doesn't seem to pick up the character at all. Specifically, "serial.readable()" never returns '1' meaning there is no character to read at all. When I do a loop-back test using both "serial.readable()" and "serial rx interrupt" using a single controller(meaning that the transmitter and receiver connected to the same controller), it works fine in both cases.. The problem arises when I attach the receiver and transmitter to two different LPC1768's. The receiver and controller are powered by their corresponding controllers via GND and VU pins
Transmitter
#include "mbed.h" Serial pc(USBTX, USBRX); // tx, rx Serial device(p9, p10); // tx, rx DigitalOut myled1(LED1); int main() { device.baud(2400); while (1) { //RF Transmit Code if (pc.readable()==0) { myled1 = 1; //Send 10101010 pattern when idle to keep receiver in sync and locked to transmitter //When receiver loses the sync lock (Around 30MS with no data change seen) it starts sending out noise device.putc(0xAA); myled1 = 0; } else //Send out the real data whenever a key is typed { pc.printf("Sent character is: "); pc.putc(device.putc(pc.getc())); pc.printf("\n"); } } }
Receiver
#include "mbed.h" Serial pc(USBTX, USBRX); // tx, rx Serial device(p13, p14); // tx, rx DigitalOut myled1(LED1); DigitalOut myled2(LED2); int main() { char temp=0; device.baud(2400); while (1) { myled1=1; //RF Receive Code if(device.readable()) { myled2 = 1; temp=device.getc(); //Ignore Sync pattern and do not pass on to PC if (temp!=0xAA) { pc.printf("Received character is: "); pc.putc(temp); pc.printf("\n"); } myled2 = 0; } } }
If I remove the "if(device.readable())" condition, it gets stuck in device.getc(). Any idea why this isn't working? Any other ways to read data via RF 434MHz modules? Any help would be appreciated. Thanks in advance.
Question relating to:
Assigned to
6 years, 6 months ago.This means that the question has been accepted and is being worked on.
What about (TX => RX) and (RX => TX) connections? Is it OK?
posted by LORDTEK LORDTEK 19 Jan 2015I am having a similar issue with C027 platform. Have you solved your problem?
posted by Nicolás Sosa 13 Apr 2016i am also having same issue
posted by gautam tripathi 23 Jun 2016I am facing the same problem.Help!!!
posted by Malay Tarte 05 Mar 2017I have the same problem!
posted by Hendrik Becker 17 Mar 2017I have the exact same issue. Any developments?
posted by Dhruv Laad 27 Nov 2017I have the same issue. Have you solved your problem?
posted by Matthew bellami 28 Feb 2018Why does anyone waste their time on MBED support? They just have a bunch of know-nothings pasting links to useless documentation that people can find on their own. This is sad.
posted by Peter Backeris 01 Apr 2019I have the same issue with a KL25Z. device.readable() never returns a true value. If I remove and let the device.getc block waiting on received data, it works when the data buffers. Would be nice if he readable() part worked to keep my code from blocking...
posted by Jeff Lewis 22 Apr 2019