Shop OBEX P1 Docs P2 Docs Learn Events
Xbee problems — Parallax Forums

Xbee problems

CrosswindsCrosswinds Posts: 182
edited 2013-03-26 15:35 in Propeller 1
Hello!


I have just recieved my two xbee series 1 units.


Hooked everything up on seperate boards.


And run these test programs on them:
Sender:

CON
_xinfreq = 5_000_000
_clkmode = xtal1 + pll16x

OBJ 
    XB : "XBee_Object"
    
          

Pub Start

DIRA[16]~~

XB.start(6,7,0,9600)           ' XBee Comms - RX,TX, Mode, Baud
    XB.AT_Init                     ' Initialize for fast AT command use - 5 second delay to perform
    XB.AT_ConfigVal(string("ATMY"),$5) ' Set MY address to 5
    
    
    
    repeat

      OUTA[16]~~
      waitcnt(clkfreq/2 + cnt)
      XB.str(string("Hello!",13))    ' Send a string
          
      outa[16]~
      waitcnt(clkfreq/2 +cnt)
      
      

Reciever:

CON
_xinfreq = 5_000_000
_clkmode = xtal1 + pll16x

VAR

long Mystr


OBJ 
    XB : "XBee_Object"
    pst : "Parallax Serial Terminal"
    




Pub Start
    XB.start(16,17,0,9600)           ' XBee Comms - RX,TX, Mode, Baud
    XB.AT_Init                     ' Initialize for fast AT command use - 5 second delay to perform
    XB.AT_ConfigVal(string("ATMY"),$5) ' Set MY address to 5
    pst.Start(115_200)
    
    
    repeat


      
      
      XB.rxStr(MyStr)
      
      
      pst.str(Mystr)
      
      



i do get a "OKOK" in the PST after starting the reciever up.

But nothing else..

Any ideas?

Probably did something stupid since i was in a hurry to get this going :)

Comments

  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-03-24 14:18
    It's hard to tell without the indentation.

    attachment.php?attachmentid=78421&d=1297987572
  • CrosswindsCrosswinds Posts: 182
    edited 2013-03-24 14:34
    Sorry for that!

    Fixed.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-03-24 14:55
    Do have a link to the code you're using.

    I'm not familiar with the string usage though I bet it's correct.

    Maybe a picture of your setup will let someone catch something you're not seeing?
  • CrosswindsCrosswinds Posts: 182
    edited 2013-03-24 14:59
    Duane Degn wrote: »
    Do have a link to the code you're using.

    I'm not familiar with the string usage though I bet it's correct.

    Maybe a picture of your setup will let someone catch something you're not seeing?


    Hello!

    The code is taken from the very beginning of the xbee object. There´s an example there.

    Sorry dont have a picture on it. But it is connected like so:

    Sender:

    Xbee pin 1 -> 3.3v
    Xbee pin2 -> prop 7
    Xbee pin3 -> Prop 6 (note i have tried to invert these.)
    xbee pin 10 -> GND

    Same way for reciever but different prop pins. And i do get a "OKOK" from that one.
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2013-03-24 15:24
    You need to set the destination address on the sender:

    XB.AT_ConfigVal(string("ATMYDL"),$5) ' Set DL address to 5
  • CrosswindsCrosswinds Posts: 182
    edited 2013-03-24 15:28
    You need to set the destination address on the sender:

    XB.AT_ConfigVal(string("ATMYDL"),$5) ' Set DL address to 5



    Thank you! So i should replace MY with DL?

    In the example code, it is the sender i think?
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2013-03-24 16:55
    When the receiver address is $5, so the sender has to have it's DL (destination Low) set to that also. Replace MY with DL. In your scenario the MY on the sender does not matter, but if it would if you move on to bidirectional transmission.

    By the way, XBees series 1 as they come from the factory are set with both MY=0 and DL =0, so they can communicate with one another out of the box.
  • CrosswindsCrosswinds Posts: 182
    edited 2013-03-24 17:00
    When the receiver address is $5, so the sender has to have it's DL (destination Low) set to that also. Replace MY with DL. In your scenario the MY on the sender does not matter, but if it would if you move on to bidirectional transmission.

    By the way, XBees series 1 as they come from the factory are set with both MY=0 and DL =0, so they can communicate with one another out of the box.

    Thank you again!

    So this means that if i didnt include that setting from the beginning, it should have worked right away?

    If i want bi-directional i should set these on both ends, right?
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2013-03-25 21:00
    Yes, it should work as a serial line replacement right out of the box. It may still have its original settings in its eeprom. When you power up the XBee, it will read those original settings and both the rx and tx will return to DL=0 and MY=0. In your program, you change MY to 5, but you have not stored that setting in the eeprom. It takes as special command (ATWR) to do that.

    I noticed another problem with your rx routine. The following code does not add up:
    [SIZE=1][FONT=courier new]long Mystr
    
    XB.rxStr(MyStr)
    pst.str(Mystr)[/FONT][/SIZE]
    

    Mystr as a long consists of 4 bytes, but your tx routine is trying to send "hello",CR, which needs 6 bytes. The usual way to define that is
    byte MyStr[7]
    One extra byte so that it can hold a null at the end, which is what signals the end of string.
    Furthermore, commands that act on strings usually require the address of the string, like this:
    XB.rxStr(@MyStr)
    pst.str(@Mystr)

    Good luck! You have a couple of new things going on here!
  • CrosswindsCrosswinds Posts: 182
    edited 2013-03-26 15:35
    Yes, it should work as a serial line replacement right out of the box. It may still have its original settings in its eeprom. When you power up the XBee, it will read those original settings and both the rx and tx will return to DL=0 and MY=0. In your program, you change MY to 5, but you have not stored that setting in the eeprom. It takes as special command (ATWR) to do that.

    I noticed another problem with your rx routine. The following code does not add up:
    [SIZE=1][FONT=courier new]long Mystr
    
    XB.rxStr(MyStr)
    pst.str(Mystr)[/FONT][/SIZE]
    

    Mystr as a long consists of 4 bytes, but your tx routine is trying to send "hello",CR, which needs 6 bytes. The usual way to define that is
    byte MyStr[7]
    One extra byte so that it can hold a null at the end, which is what signals the end of string.
    Furthermore, commands that act on strings usually require the address of the string, like this:
    XB.rxStr(@MyStr)
    pst.str(@Mystr)

    Good luck! You have a couple of new things going on here!


    Thank you for your input and tips! Very helpful.

    Have to change the things you pointed out! As soon as i find a new project for spin, i always struggle a bit comming back to Spin. Make alot more projects in C++. Even though, i find the spin language a lot easier to learn.
Sign In or Register to comment.