XBee sending garbage to Arduino?

Hi

I'm running an Xbee 868 MHz attached directly to the Arduino and all comms work fine, except when the XBee is not receiving any RF data, it's outputting garbage - an endless stream of 0xFFs.

The datasheet says that the line idles high, but that shouldn't cause the UART to receive data (start bits are low).

I'm using it in transparent mode, i.e. no API frames.

Could it be because I'm not using a level shifter?

Could it be because I'm not using a level shifter?

the xbee is a 3.3v device, it is highly likely you have damaged it if you are sending it 5v

The 0xFF is also known as a -1 which is what Serial.read() returns when there is no data to read. Calling Serial.available() first, or knowing that Serial.read() returns -1 when there is no data to read are two ways to stop the "endless stream of 0xFFs".

Your code, not the XBee, is what is outputting garbage.

Thank you both for replies.

UltraMagnus, XBees are 5 V tolerant and my unit is working fine except for the garbage problem. I've tried hooking up a voltage divider to pull the DIN to 3v2 and the problem persisted.

PaulS, Serial.available() is always returning 127 because the buffer is permanently filled. It is only because I'm reading it as fast as possible (and dropping any invalid data) that I'm able to get my data through. It is okay at 9600 baud, but at faster rates the 0xffs get mixed into valid data.

Note that this only happens on the 868 MHz version - XBee-PRO Series 2 that I also work with do not show this behavior.

You might want to figure out how not to have your serial buffer always filled. Turn down the spigot on the other end! Use a bidirectional request-response protocol! Something.

You're getting the 0xff's at faster speeds because you're still ignoring Serial.available() but now you aren't jamming the pipe full all the time, so you don't always have data ready.

Or at least that's the theory...if you post the code for the sender and receiver it may become clearer.

I'm sorry for not being clear.

There is no traffic sent by the XBee UART to the Arduino that I know of (i.e. no RF traffic is being received by the XBee).

The RX/TX LEDs are permanently lit (blinking fast, around 50 Hz).

Serial.available() returns 127 no matter what (what makes you think I'm ignoring it?).

This is the offending code, simplified to its most primitive form:

char c;

void setup() {
    Serial.begin(9600);
}

void loop() {
    if (Serial.available()) { // Serial.available() == 127 at all times
        c = Serial.read();
    }
    
    // at this point c == 255 if there is no traffic sent from the XBee
}

What does the code on the sender look like? There is nothing in the receiver code that supports the comments.

Once again, there is no sender. Or more exactly even when there is no sender the problem persists. If there is a sender (doing nothing more than a Serial.write(buf, len) every 30 s) I'm getting good frames in (with 0xff garbage in between them). When I remove the sender (physically cutting power to it), I stop receiving telemetry frames (obviously) and only the 0xff stream remains.

I added this to my loop:

if (Serial.available() != 127) {
    led.strobe(255);
}

This would stop the code for 255 seconds, blinking the LED at 10 Hz on pin 13, but this never ever happened. Buffer is permanently filled.

Once again, there is no sender.

Then what is the XBee for? It's a receiver for some other device (generally another XBee) sending data over-the-air. If nothing is sending data to the XBee, why not just remove the XBee and solve the problem?

Not trying to be rude, but please re-read the previous post - if there's another xbee present (the sender), I'm getting good data and garbage; when I remove the sender I'm getting just the garbage.

With my XBee setup, I get good data when they are both powered up and in range, and NO data when one is powered off.

Since that is not the case for you, I would suspect (but have no proof) that there is a configuration issue. Can you tell us what steps you followed to configure the XBees?

The only other factor that could come into play is interference from something else operating on the same (or nearly the same) frequency. Changing some of the configuration settings might fix the interference.

UltraMagnus, XBees are 5 V tolerant and my unit is working fine except for the garbage problem.

http://www.digi.com/support/kbase/kbaseresultdetl.jsp?kb=160

To be clear, the inputs to the XBee module are NOT 5V tolerant.

:-/

UltraMagnus, I generally trust a datasheet before a FAQ entry.

http://ftp1.digi.com/support/documentation/90001020_a.pdf

page 5: "UART 3.3V CMOS (5V tolerant)" page 8: all UART pins have 5 V maximum

There's probably an electrical difference between the XBee, XBee-PRO and the 868/900 variants.

To all: ATVR returns 0x0000 for some reason. I suspect a colleague has flashed the firmware with something unofficial, which could definitely be the cause. I'll report back tomorrow when I get a hold of him. Thanks for assistance.