Shop OBEX P1 Docs P2 Docs Learn Events
BS2 & XBee w/n receive from BS1 & XBee — Parallax Forums

BS2 & XBee w/n receive from BS1 & XBee

FalconFalcon Posts: 191
edited 2012-03-13 16:42 in Accessories
I am working on a remote transmitter based on a BS1 and a Series 1 XBee. For now I am just trying to send the condition of a switch closure, but will use a DS1620 for temperature data after I get this chunk of code working. I fully subscribe to the "small bites" methodology.
I first used a pair of BS2's because I'm more familiar with that code. I got it to work with some help from Tracy Allen. So now I'm essentially "porting" the Transmitter part of this code to the BS1. Simplified BS2 Receiver code:
' {$STAMP BS2}
' {$PBASIC 2.5}

' *************** Constants & PIN Declarations ***********
Baud            CON     396                     '2400 baud
Rx              PIN     15    ' XBee DIN
Tx              PIN     14    ' XBee Dout
RTS             PIN     11    ' XBee RTS - Used later

' ************** Variable Declarations ******************
Switch          VAR     Byte

PAUSE 500
DEBUG "Configuring XBee...",CR
PAUSE 2000                          ' Guard Time
SEROUT Tx,Baud,["+++"]              ' Command mode sequence
PAUSE 2000                          ' Guard Time
SEROUT Tx,Baud,["ATD6 1,CN",CR]     ' RTS enable (D6 1)
                           
' ************** Main LOOP ******************************
PAUSE 500                     ' 1/2 second pause to stabilize comms
DEBUG "Awaiting Byte Data...",CR

DO

  SERIN Rx\RTS,Baud,500,TimeOut1,[DEC Switch] ' Use Timeout to wait for byte
       TimeOut1:

DEBUG CRSRXY, 0, 5, DEC Switch, CR

LOOP


Simplified BS1 Transmitter code:
' {$STAMP BS1}
' {$PBASIC 1.0}

SYMBOL  Switch = B11

SYMBOL  XB_Sleep  = 3
SYMBOL  TX   = 4          ' XBee TX
SYMBOL  Win  = 7
SYMBOL  BAUD = N2400

 DEBUG "Configuring XBee...",CR
  PAUSE 2000                          ' Guard Time
  SEROUT Tx,Baud,("+++")              ' Command mode sequence
  PAUSE 2000                          ' Guard Time
  SEROUT Tx,Baud,("ATD6 1,CN")     ' RTS enable (D6 1)
  PAUSE 1000
  SEROUT Tx,Baud,("ATBD 1,CN")     ' Change BAUD rate to 2400
  SEROUT Tx,Baud,("ATSM 1")

main:
    Switch = PIN7                   'load with current switch state
    DEBUG #Switch, CR
    SEROUT Tx, Baud, (#Switch)
    PAUSE 15
    DEBUG CLS
GOTO main

Circuit includes switch on Pin 7 with a 10k pull-up resistor and the XBee connections as per the Tutorial V1.0

The BS1 Transmitter code will, on its own, display the correct info via the DEBUG statement. However the corresponding switch condition is not transmitted to and/or displayed on the Receiver DEBUG statement.
The three major difference between the BS1 and BS2 TX code are:
1) Baud rates limited to 2400 on the BS1; Changed code to accomodate BS1 limit
2) The Decimal modifier for the BS1 is # and is DEC for the BS2
3) The format of the SEROUT statements as follows:

I think the problem may be the format of the SEROUT statement for the BS1 vs. BS2. For the BS2, the XBee configuration SEROUT statements include a CR inside the brackets, i.e. SEROUT Tx,Baud,["ATD6 1,CN",CR]. The BS1 will not allow the CR so I'm forced to use SEROUT Tx,Baud,("ATD6 1,CN"). I don't think the bracket vs. parenthesis is a problem, but I think the XBee is looking for that CR and is not getting it with what is allowed by the BS1 code formatting.

Has anyone sucessfully used a BS1 to control an XBee? It seems that the XBee came out way after the BS1 and most people have only interfaced it with the BS2.

Any and all comments, suggestions are welcome

falcon

Comments

  • FalconFalcon Posts: 191
    edited 2012-03-13 16:42
    I think I narrowed the problem down to the inability to use the following statement: in the BS1 editor. Specifically the CR
    SEROUT Tx, Baud, (#Switch, CR)
    

    I still don't know if the actual problem is on the TX or RX end though. I confirmed that the CR must be in the SEROUT statement by going back to the BS2 & XBee transmitter configuration and trying it with and without the CR. While the BS2 editor would not cause an error with the CR in the SEROUT statement (as the BS1 did), that data only successfully made it to the Receiver with the CR present.


    So, I need to use the above statement to get the data to the Receiver, but the BS1 editor will not accept that statement.

    I tried using the following statement with the CR character from the ASCII table but that did not correct the issue either.
    SEROUT Tx, Baud, (#Switch, #13)
    

    Is there a work-around for getting that CR in the BS1 SEROUT statement?

    falcon
Sign In or Register to comment.