Shop OBEX P1 Docs P2 Docs Learn Events
Trouble "catching" inbound XBee data with RX in a loop — Parallax Forums

Trouble "catching" inbound XBee data with RX in a loop

FalconFalcon Posts: 191
edited 2012-04-20 16:20 in Accessories
Hello all,
Working on my project in small steps, I have one XBee sending a byte of DS1307 temperature data to another successfully.

I'm now trying to insert that receiver code into the main project which is a 7-Slot (BS2Px) loop that includes the following steps:

receives13 inbound bytes
processes those bytes into SPRAM
sends all data to an LCD
and, depending on which bytes have changed,
sends updates to a PINK
sends commands to a V-Stamp voice module




I'm unable to receive the temperature data when all Slots are included in the loop.

I do successfully receive the temperature data if I execute the initialization and then go into a loop of just the Slot with the XBee receive code.

I'm sure I'm missing the inbound data from the XBee trabsmitter while the rest of the main unit loop is executing..

Questions: How can I better receive that inbound XBee data?

Should I increase the length of the time-out in the SERIN command?

Is it possible to have the receiver ackknowledge the inbound data before the loop continues to execute?



All suggestions are welcomed.

falcon

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2012-04-19 20:31
    You have to use flow control in the SERIN statement. The problem that you're running into is that the xBee transmits data to the Stamp while the Stamp is busy doing something other than a SERIN. You'll need an extra I/O pin connected to the xBee's CTS output pin. The SERIN statement will make this extra I/O pin HIGH when it's ready to receive data and will leave it LOW when the SERIN finishes (and is no longer "listening"). The xBee will stop sending when CTS goes LOW and will buffer anything that comes in until CTS goes HIGH again. See page 409 of the Stamp Manual.

    I may have CTS backwards in that it may be HIGH to stop sending and LOW to allow sending from the xBee. You'll have to check the Stamp and xBee documentation.
  • FalconFalcon Posts: 191
    edited 2012-04-20 05:59
    Mike,
    I appreciate your response.
    Page 11 of the Getting Started with XBee Modules mentions CTS but, if I understand, it applies to the transmitting end.

    I have RTS implemented in my code as follows.

    I’m using the following initialization code which includes the ATD6 1 statement to activate RTS:
    DEBUG CLS,"Configuring XBee...",CR
    PAUSE 3000                      ' Guard time
    SEROUT XBTx,XBBaud,["+++"]          ' Command Mode Sequence
    PAUSE 2000                      ' Guard time
    SEROUT XBTx,XBBaud,["ATGT 3,MY 0,D6 1",CR]    ' Set low guard time
    SEROUT XBTX,XBBaud,["ATCN",CR]      ' Exit Command Mode
    

    The following shows the pin assignments for the XBee :
    XBRx            PIN     0                  ' XBee DOUT
    XBTx            PIN     1                  ' XBee DIN
    RTS             PIN     2                  ' XBee RTS
    


    And this code is in the main loop:
    main:
      SERIN XBRx\RTS,XBBaud,1500,UpdateTOut,[DataIn]  ' Wait for "A" with timout
        SELECT DataIn
    
          CASE "A"
            SERIN XBRx\RTS,XBBaud,500,UpdateTOut,[DEC TempIn]
            DEBUG CRSRXY, 15, 33, BIN TempIn.BIT7, CR      'Displays WindowA Condition
            tF = TempIn * 9 / 10 + 32
            DEBUG CRSRXY, 35, 33, DEC tF,CR ' show the result on the PC screen
            DEBUG CRSRXY, 39, 33, "F", CR ' show the result on the PC screen
    

    Do you see any glaring mistakes in how this is written?

    falcon
  • Mike GreenMike Green Posts: 23,101
    edited 2012-04-20 12:20
    Sorry about the RTS / CTS confusion (see here). In any event, you're using output flow control on the SERIN statements. I don't see anything obviously wrong although I don't have the documentation on the xBee AT commands to check against. Is the xBee responding appropriately to the configuration commands?
  • FalconFalcon Posts: 191
    edited 2012-04-20 16:20
    Mike Green wrote: »
    Sorry about the RTS / CTS confusion (see here). In any event, you're using output flow control on the SERIN statements. I don't see anything obviously wrong although I don't have the documentation on the xBee AT commands to check against. Is the xBee responding appropriately to the configuration commands?

    Yes.

    If I run the initialization code, then create a loop that only contains the XBee receive code, I do receive the temperature data. So I know the actual Receive code works.

    When I start including parts of the other 7 Slots, I no longer receive the data. I do have a number of GET and PUT statements . Do they slow down the execution enough to cause a problem?


    What is the logic used to determine Timeout, and WAIT modifier time periods?

    In the following XBee receiver code, what length of Timeout period should I use for the main SERIN statement, and what length of Timeout period should I use for the SERIN statements within the SELECT-CASE?
    main:
      SERIN XBRx\RTS,XBBaud,1000,UpdateTOut,[DataIn]  ' Wait for "A" with timout
        SELECT DataIn
    
          CASE "A"
            SERIN XBRx\RTS,XBBaud,200,UpdateTOut,[DEC TempIn]
            DEBUG CRSRXY, 15, 33, BIN TempIn.BIT7, CR      'Displays WindowA Condition
            tF = TempIn * 9 / 10 + 32
            DEBUG CRSRXY, 35, 33, "   ",CR
            DEBUG CRSRXY, 35, 33, DEC tF,CR ' show the result on the PC screen
            DEBUG CRSRXY, 39, 33, "F", CR ' show the result on the PC screen
    
          CASE "B"
    
            SERIN XBRx\RTS,XBBaud,200,UpdateTOut,[DEC TempIn]
            DEBUG CRSRXY, 15, 34, BIN TempIn.BIT7, CR      'Displays WindowA Condition
            tF = TempIn * 9 / 10 + 32
            DEBUG CRSRXY, 35, 34, "   ",CR
            DEBUG CRSRXY, 35, 34, DEC tF,CR ' show the result on the PC screen
            DEBUG CRSRXY, 39, 34, "F", CR ' show the result on the PC screen
    
    
          CASE "C"
    
            SERIN XBRx\RTS,XBBaud,200,UpdateTOut,[DEC TempIn]
            DEBUG CRSRXY, 15, 35, BIN TempIn.BIT7, CR      'Displays WindowA Condition
            tF = TempIn * 9 / 10 + 32
            DEBUG CRSRXY, 35, 35, "   ",CR
            DEBUG CRSRXY, 35, 35, DEC tF,CR ' show the result on the PC screen
            DEBUG CRSRXY, 39, 35, "F", CR ' show the result on the PC screen
    

    Within the 8-Slot main loop I have a hard-wired SERIN from a remote BS2P40 using RTS and the WAIT modifier. How should I set determine the proper length for the Timeout for that SERIN? Could the WAIT modifier here be holding things up too long?

    falcon
Sign In or Register to comment.