SEROUT Not Working
ldarnell
Posts: 4
I am working on an XBee project using the BS2, but nothing I do seems to make the BS2 SEROUT command work. I followed the example (shown below) that allows you to type a character on the first device and have a loop back on the second device. But, the second device never receives anything from the first. I threw in some DEBUG commands on the second device, but nothing ever gets there.
I know my XBee's are configured properly as I have written apps in Java, C#, and Python that can all communicate with each other. However, the BS2 seems to ignore the SEROUT command. I've tried this now on the BS HomeWork Board as well as on the Board of Education with a BS2 loaded, but neither seem to work. Heck, I even tried connecting PINs 0 to 2 directly in hopes that when the data is sent out of PIN 0 it will instantly be picked up on PIN 2 (without going thru the XBee), but that didn't seem to work either.
What do I need to do to get the SEROUT command to actually transmit data?
I know my XBee's are configured properly as I have written apps in Java, C#, and Python that can all communicate with each other. However, the BS2 seems to ignore the SEROUT command. I've tried this now on the BS HomeWork Board as well as on the Board of Education with a BS2 loaded, but neither seem to work. Heck, I even tried connecting PINs 0 to 2 directly in hopes that when the data is sent out of PIN 0 it will instantly be picked up on PIN 2 (without going thru the XBee), but that didn't seem to work either.
What do I need to do to get the SEROUT command to actually transmit data?
' {$STAMP BS2}' {$PBASIC 2.5} ' Requires remote XBee in loopback mode (DIN connected to DOUT) Baud CON 84 ' 9600 baud non-inverted Rx PIN 2 ' XBee DOUT Tx PIN 0 ' XBee DIN temp VAR Byte ' Temporary variable PAUSE 500 ' 1/2 second pause to stabilize DO DEBUG CLS, "Type a character: " ' Prompt for character DEBUGIN temp ' Catch user response SEROUT Tx, Baud, [temp] ' Send to transmitting XBee <-------- This never transmits SERIN Rx, Baud, [temp] ' Get echo from receiving XBee SEROUT 16, Baud, [CR, "You entered: " , temp] ' Display result PAUSE 1500 ' Wait 1-1/2 seconds LOOP
Comments
Connecting pin 2 to pin 0 won't work because the SEROUT and SERIN occur at different times. That may be why you're not seeing the echo back from the xBee ... it's hard to tell. Usually you use handshaking to make the xBee wait until the Stamp is waiting at the SERIN. Look at the description of the SERIN statement in the Stamp Reference Manual. You'll have to configure the xBee differently to use handshaking.
Typically, you'd use: SERIN Rx\RxRdy, Baud, [temp]
RxRdy would be: RxRdy PIN 1 ' or something like this. See page 409-410 in the Manual.
The SERIN on the second board works fine. Below is a snippet of that working code.
I have tested that this code works by sending messages from my Java, C#, and Python apps, all of which send messages just fine and are read by the second XBee.
Also, whenever I connect a multimeter to PIN 0 (TX) on the first board, I never get any reading above 0, indicating that nothing is coming out of that PIN. I've tried using other PINs and have swapped the XBees, but nothing seems to be working.
Here is the app that I'm trying to make work. I've tried it with CTS and without. I've also tried adding a pause between SEROUT and SERIN just in case, but that didn't work either. I've also tried submitting a single Byte, DEC, and things other than the Byte array as shown here.
Unless you've somehow destroyed your Stamp pin 0 or there's a bad solder connection or board trace to it, the SEROUT will work. As I mentioned, unless you use handshaking, it's quite possible that the xBee sends data to the Stamp when the Stamp isn't listening (immediately after the SEROUT and before the SERIN starts waiting for input). If you have another USB to serial adapter, logic analyzer, or serial LCD, you might try to see what's coming out of pin 0. A multimeter may not give you any indication of data present because of its slow response. Consider calling Parallax Tech Support tomorrow.
For now I am going to skip the BS2 and send commands directly from the XBee. Since my project is limited on space, using the XBee without a microcontroller might be the best choice anyways. I was just hoping I could squeeze in the BS2 to handle a little bit of logic before things are sent across the XBee.
Thanks for all your help! I greatly appreciate it!
I take it you mean a level shifter?
As Mike points out a multimeter isn't a reliable way to see if there's activity on a pin. The meter's response can be too slow for it to catch the signals (I've been fooled by this several times myself).
Also keep in mind the BS2 doesn't have a UART buffer. The SERIN statement has to be used before the data is sent or if will be missed.
If you know how to use an Arduino, you might want to get a cheap clone to use with the XBee. Having an UART buffer makes a big difference in applications like this.
-Phil
According to Digi, makers of the XBee module, the I/O pins are not 5V tolerant and a resistor is not a suitable method for getting 5V signals into the XBee Module. A 3.3V regulator means the XBee is powered from 3.3V, but 5V signals coming into the I/O pins can and will damage it and may be causing other issues. This is why we have the XBee 5V/3.3V Adapter.