Report
4 years, 9 months 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:

Rapid Prototyping for general microcontroller applications, Ethernet, USB and 32-bit ARM® Cortex™-M3 based designs

What happens if you connect the two LPC1768s directly with UARTs and GND? If that works, and I assume it will, it must be an issue with your transmitter/receiver.

posted by Erik Olieman 22 Dec 2014

Hey, thanks for the reply. If I connect the two LPC1768s directly, it is able to communicate. But when I do a loopback test also, it is able to communicate. Now I am confused. Here is the loopback test code.

#include "mbed.h"
 
Serial pc(USBTX, USBRX); // tx, rx
Serial device(p9, p10);  // tx, rx
DigitalOut myled1(LED1);
DigitalOut myled2(LED2);
//RF link demo using low-cost Sparkfun RF transmitter and receiver modules
//LEDs indicate link activity
//Characters typed in PC terminal windows will echo back using RF link
int main() {
    char temp=0;
    device.baud(2400);
    while (1) {
    
        //RF Transmit Code
        if (pc.readable()==0) {
            myled1 = 1;
            //Send 10101010 pattern when idle to keep receivers AGC gain locked to transmitters signal
            //When receiver loses the signal lock (Around 10-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.putc(device.putc(pc.getc()));
            
        //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.putc(temp);
            myled2 = 0;
        }
    }
}
posted by Amoghavarsha Ullur 25 Dec 2014
Comment on this question

1 Answer

4 years, 8 months ago.

Didn't notice you replied, I don't get a mail when it is not a reply on my own answer.

If it works when the LPC1768s are directly connected, and also when both transceivers connected to one LPC1768, then I really think it must be something like a wiring issue in the regular case.

Do you have a scope or logic analyser to verify if the receiver outputs any data?

I am afraid I don't have either of them :(

Here is the wiring details:

/media/uploads/Amoghavarsha/capture.png

Is there a way to check if the issue is in the transmitter or receiver?

posted by Amoghavarsha Ullur 02 Jan 2015

There are cheap digital TV USB receivers which can also work as spectrum analyzer, they can show you if anything is being transmitted. But that also isn't a simple check.

If you have a multimeter and it is transmitting continiously 0xAA, then on your receiver output you should measure something between 1.5V and 2V (assuming it runs on 3.3V, if it runs on 5V it should be somewhere between 2V and 3V).

In your above posted code the receiver is connected to p14, while in your wiring details here you say p10, sure your code is listening on the correct pin?

posted by Erik Olieman 02 Jan 2015

You need to log in to post a question