Shop OBEX P1 Docs P2 Docs Learn Events
Simple XBee API implementation not working on propeller — Parallax Forums

Simple XBee API implementation not working on propeller

NicopowersNicopowers Posts: 12
edited 2016-08-12 23:25 in Propeller 1
Hi everyone,

I put together a VERY simple API implementation and I can not get it to work!!! I think this will serve as a very good example on how to setup a basic XBee API communication system using the propeller. I wrote codes for an XBee router and an XBee Coordinator. I do not know what I am doing wrong! I'm also going to attach the archived projects for each code, thank for UART help!

Router Code :
CON                          
  _clkmode = xtal1 + pll16x
  _xinfreq = 5_000_000
  
  ' I/O and Baud rate for XBee comms 
  XB_Rx     = 2  
  XB_Tx     = 1
  XB_Baud   = 9600

  ' XBee addresses
  DL_Addr = 0    ' Send data to this address (base)

OBJ
  XB    : "XBee_Object"
  
PUB Start 
  ' Initialize Hardware Objects
  XB.Start(XB_RX, XB_TX ,0, XB_Baud)
  XB.Delay(5000)

  repeat                     ' Accept incoming in loop

    XB.API_Str(DL_Addr,string("Hello"))
    XB.Delay(5000)          

Coordinator Code :
CON

  _clkmode = xtal1 + pll16x
  _xinfreq = 5_000_000

  ' Set pins and Baud rate for XBee comms
  XB_Rx         = 17  
  XB_Tx         = 16
  XB_Baud       = 9600
   
  ' Set pins and baud rate for PC comms  
  PC_Rx         = 31  
  PC_Tx         = 30
  PC_Baud       = 9600

  ' Set address of base unit
  MY_Addr       = 0  
OBJ

  XB    : "XBee_Object"
  PC    : "FullDuplexSerial"
 
  
PUB Start 
  ' Configure XBee & PC Comms
  PC.start(PC_Rx, PC_Tx, 0, 9600)
  XB.start(XB_Rx, XB_Tx, 0, 9600)
  XB.Delay(5000)



  PC.str(string("Coordinator in API mode ready at address:"))
  PC.dec(MY_Addr)
  
  PC.Tx(13)
  XB.Delay(5000)
  Repeat
    ProcessFrame

Pub ProcessFrame | Temp 
  '' Accepts incoming frame for data and diplay

  PC.Str(string("test"))
  XB.API_Rx                     ' wait for API data
  PC.Str(string("test2"))
  if XB.RxIdent == $81          ' If data identifier is a msg string
                                ' Display source address
     PC.Str(string(13,"Data Received from address: "))
     PC.DEC(XB.srcAddr)
                                ' Display received string
     PC.Str(string(13,"Message String   : "))
     PC.str(XB.RxData)
    
     PC.str(string(13,"RF Signal strength: "))
     PC.DEC(-XB.rxRSSI)          ' Display RSSI level   
                                 ' on sending unit

     PC.str(string(13,"------------------------------------------"))   


Comments

  • ElectrodudeElectrodude Posts: 1,657
    edited 2016-08-13 00:10
    What's address 0? I don't remember and can't find in the manual anything about 0 being special. 0xFFFF is broadcast. Is it possible it's not sending anything because it thinks it's addressed to itself, since they're both 0?

    You use the term "coordinator". Does that mean one of the XBees is in coordinator mode? What if you try it without coordinator mode?

    The configuration I usually use is just the default configuration with the following changes: API mode, my desired baud rate, and (as just a (probably dumb) convention I have) the 16 bit address set to the bottom 16 bits of the 64 bit address printed on the bottom of the XBee (also the SH and SL values), but any other unique values should work. Make sure you tell each XBee to send to the 16 bit address of the other. You could also try setting the DH and DL of each XBee to the SH and SL of the other, but I don't think that matters with API mode. Unfortunately, that XBee object doesn't support 64 bit addressing.

    What happens if you hook one XBee up to the Propeller and the other one to XCTU? Does XCTU show any packets coming in?

    Also, I see that you have a FullDuplexSerial and an XBee object, which has another FullDuplexSerial. Once you get this working, you can save some cogs by using the modified XBee object that uses fullDuplexSerial4port that I posted in your other thread.

    I'm not a moderator or anything, but is there a reason you didn't just post this in your other thread?
  • We made the following changes: We removed the constants that you mentioned in your comment and just placed a zero for the MY address of the coordinator and DL address of the Router.
    CON
    
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
    
      ' Set pins and Baud rate for XBee comms
      XB_Rx         = 17  
      XB_Tx         = 16
      XB_Baud       = 9600
       
      ' Set pins and baud rate for PC comms  
      PC_Rx         = 31  
      PC_Tx         = 30
      PC_Baud       = 9600
    
      
       
    OBJ
    
      XB    : "XBee_Object"
      PC    : "FullDuplexSerial"
     
      
    PUB Start 
      ' Configure XBee & PC Comms
      PC.start(PC_Rx, PC_Tx, 0, 9600)
      XB.start(XB_Rx, XB_Tx, 0, 9600)
      XB.Delay(5000)
    
    
    
      PC.str(string("Coordinator in API mode ready at address:"))
      PC.dec(0)
      
      PC.Tx(13)
      XB.Delay(5000)
      Repeat
        ProcessFrame
    
    Pub ProcessFrame | Temp 
      '' Accepts incoming frame for data and diplay
    
      PC.Str(string("test"))
      XB.API_Rx                     ' wait for API data
      PC.Str(string("test2"))
      if XB.RxIdent == $81          ' If data identifier is a msg string
                                    ' Display source address
         PC.Str(string(13,"Data Received from address: "))
         PC.DEC(XB.srcAddr)
                                    ' Display received string
         PC.Str(string(13,"Message String   : "))
         PC.str(XB.RxData)
        
         PC.str(string(13,"RF Signal strength: "))
         PC.DEC(-XB.rxRSSI)          ' Display RSSI level   
                                     ' on sending unit
    
         PC.str(string(13,"------------------------------------------"))   
    
    

    And the Router's Code :
    CON                          
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
      
      ' I/O and Baud rate for XBee comms 
      XB_Rx     = 1  
      XB_Tx     = 2
      XB_Baud   = 9600
    
     
      
    
    OBJ
      XB    : "XBee_Object"
      
    PUB Start 
      ' Initialize Hardware Objects
      XB.Start(XB_RX, XB_TX ,0, XB_Baud)
      XB.Delay(5000)
    
      repeat                     ' Accept incoming in loop
        
        XB.API_Tx(0,string("Hello Coordinator"))
        XB.Delay(2000)    
    

    The code appears to be looping in the XB.API_RX function where its waiting to receive data.
  • But is 0 actually the right address, or should it be something else? What does XCTU say is the 16 bit address of each XBee? The first argument to XB.API_Tx should be the 16 bit address of the receiving XBee, and the two should probably have different 16 bit addresses.
Sign In or Register to comment.