Shop OBEX P1 Docs P2 Docs Learn Events
SEROUT Not Working — Parallax Forums

SEROUT Not Working

ldarnellldarnell Posts: 4
edited 2014-05-06 14:07 in BASIC Stamp
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?
' {$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

  • Mike GreenMike Green Posts: 23,101
    edited 2014-05-04 11:25
    How do you have the two connected? The Stamps are 5V devices and the xBees are 3.3V devices. The 5V from the Stamps can destroy a 3.3V input pin structure and a 3.3V output from an xBee may not reliably trigger a 5V input on the Stamp.

    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.
  • ldarnellldarnell Posts: 4
    edited 2014-05-04 13:27
    I have a 3.3 voltage regulator sitting between Vdd on the board and Vcc on the XBees. I have several XBees, all of which work perfectly aside from using them on the BS2 board.

    The SERIN on the second board works fine. Below is a snippet of that working code.
    RX PIN 2
    Baud CON 84
    SERIN RX Baud, 1000, rxtimeout, [value]
    DEBUG CR, value
    

    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.
    ' {$STAMP BS2}' {$PBASIC 2.5}
    
    
    Baud      CON 84     ' Baud rate, 9600, 8-N-1, non-inverted, on BS2.
    RX        PIN 2      ' Receive Pin / XBee DOUT
    TX        PIN 0      ' Transmit Pin / XBee DIN
    'RTS       PIN 8
    'CTS       PIN 6
    value     VAR Byte(10)
    
    
    PAUSE 2000
    
    
    Main:
      'SEROUT TX\CTS, Baud, 100, txtimeout, ["1234567890"] ' <---- This doesn't work
      SEROUT TX, Baud, 10, ["1234567890"] ' <---- This doesn't work
      'PAUSE 1000
      SERIN RX, Baud, 1000, rxtimeout, [STR value\10] ' <---- This always works
      DEBUG CR, STR value
      GOTO Main
      END
    
    
    rxtimeout:
      DEBUG CR, "rx timeout" ' <---- This always happens until I send something from my C#, Java, or Python apps
      GOTO Main
    
    
    txtimeout:
      DEBUG CR, "tx timeout" ' <---- This never happens
      GOTO Main
    
  • Mike GreenMike Green Posts: 23,101
    edited 2014-05-04 16:06
    You have to have a power supply of 3.3V for the xBee which you will get by putting a 3.3V regulator between Vdd for the Stamp (5V) and Vcc for the xBee (3.3V). You will eventually destroy the xBee DIN I/O pin with the 5V signal from the Stamp. You'll also destroy whatever xBee pin you use for CTS. This may have already happened and that may be why the SEROUT doesn't seem to work. Parallax (and others) offer adapters that include the power supply regulator and the voltage translation buffers for the xBee.
  • ldarnellldarnell Posts: 4
    edited 2014-05-04 16:16
    As mentioned, I already have a 3.3 voltage regulator between the stamp and the XBee. I also have a 220 ohm resistor going to the CTS & DIN PINs on the XBee. I also know that the XBee and its PINs are working correctly because I can connect it to other devices such as the Arduino and the XBee Explorer dongle which all work fine.
  • Mike GreenMike Green Posts: 23,101
    edited 2014-05-04 16:40
    Good. The 220 Ohm resistors will protect the input pins.

    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.
  • ldarnellldarnell Posts: 4
    edited 2014-05-04 17:07
    Hmmm? Both the Board of Education and the HomeWork Board are brand new. I don't think I've had time to break them .... yet. :-) I'll do some snooping to see what P0 is spitting out. When I use the debugger, the "TX" indicator in the upper-right never lights up telling me that nothing is actually going out. But, again, I'll keep looking into that.

    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!
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-05-04 18:13
    ldarnell wrote: »
    As mentioned, I already have a 3.3 voltage regulator between the stamp and the XBee.

    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 Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2014-05-04 18:28
    After the first SEROUT, the output pin should be marking (high), so a multimeter will be able to detect that state. Since you're reading zero volts, try a different pin for TX, in case the Stamp got damaged somehow. Also, make sure that the XBee is configured for 9600 baud and no handshaking.

    -Phil
  • Mike GreenMike Green Posts: 23,101
    edited 2014-05-04 18:30
    Another option would be to use a Propeller Mini. This has 5V and 3.3V regulators on the module and connects directly to 3.3V devices (although the 220 Ohm resistors are still a good idea). You can program it in C or Spin and there are a variety of serial port drivers to choose from (and they're buffered).
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2014-05-06 14:07
    ldarnell wrote: »
    As mentioned, I already have a 3.3 voltage regulator between the stamp and the XBee. I also have a 220 ohm resistor going to the CTS & DIN PINs on the XBee. I also know that the XBee and its PINs are working correctly because I can connect it to other devices such as the Arduino and the XBee Explorer dongle which all work fine.

    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.
Sign In or Register to comment.