Arduino Forum

Using Arduino => Networking, Protocols, and Devices => Topic started by: agmotes on Apr 23, 2019, 03:14 pm

Title: Xbee PRO S3B in API mode, inconsistent communication.
Post by: agmotes on Apr 23, 2019, 03:14 pm
Hello everyone,

I'm currently developing a system for rapidly exchanging information from a datalogger system (a MEGA with sensors) to an XBee Pro-900 S3B, receiving on another Xbee Pro-900 S3B. The receiver at this point can be either another MEGA or a laptop and XCTU. I have tried the TX/RX lines for this, and run into problems with flow control and the Xbee's locking up. Since the end-application will be in a place where manual resets are difficult, I would prefer to avoid that, and so am attempting to use both Xbees in API mode.

Some starting points:


My test setup consists of:

PC -> usb -> MEGA -> Xbee1 -----> Xbee2 -> PC/XCTU

The MEGA is sending a 100 byte test packet with the appropriate header info and checksum, and then waits for a 'sucessful' transmit status from Xbee2 before proceeding with the next package of data.

My problem is that the larger data chunks going from Xbee1 to Xbee2 never show up in the XCTU console, and any frames sent from Xbee2 to Xbee1 will either:


In the beginning of my receive program, I have a loop that looks for the start byte (0x7E) for 300 attempts before kicking out:

Quote
while ((val != 0x7E) && (kickOut <= 300)) {      // Find the start byte
    digitalWrite(SS_PIN, LOW);                            // if no start byte is found
    //delay(1);
    val = SPI.transfer(0);                                      // within 300 tries, then abort
    digitalWrite(SS_PIN, HIGH);                           // the while loop
   
       #ifdef DEBUG
      usb.println(val,HEX);
    #endif


    kickOut++;                                
  } 


The debug code catches all of the message, but misses the starting byte by just a few bits (there is always a value where the 7E should be, its just not 7E, like its being cut off. I have tried everything there to catch those front bits, but can't get it to work. Since I'm trying to stay quick and low memory, I would prefer to catch the 7E byte properly, as all of my packet parsing runs from that point. Any suggestions on that?

My 2nd problem is that, although my debug code prints the right package data frame from Xbee1 to Xbee2 (it has a correct address, correct length, correct checksum), I cannot get Xbee2 to notice it. If i load a previous sketch with the exact same header and checksum method with a smaller package, then it works just fine. 

I've tried 2 different methods:


Neither seem to work, even if I drop the SPI clock to 500kHz (the xbee can supposedly handle 2.5MHz).
I've gotten mixed info on the xbee depending on what version it is.


Any help would be greatly appreciated.
Title: Re: Xbee PRO S3B in API mode, inconsistent communication.
Post by: PaulS on Apr 23, 2019, 05:49 pm
Code: [Select]
    val = SPI.transfer(0);                                      // within 300 tries, then abort
What are you transferring the data to? Not the XBee, that's for sure.

Code: [Select]
       #ifdef DEBUG
      usb.println(val,HEX);
    #endif

What class is usb an instance of?
Title: Re: Xbee PRO S3B in API mode, inconsistent communication.
Post by: agmotes on Apr 23, 2019, 06:21 pm
My understanding is that reading data from an SPI slave device goes like this:

Code: [Select]
uint8_t derp;

derp = SPI.transfer(0);



where a zero is "transferred" to the device, because it'll ignore anything that doesn't begin with a 0x7E, and will assign whatever is in the SPI receive register to the variable. Is that not the case here?

Code: [Select]
val = SPI.transfer(0);                                      // within 300 tries, then abort

my intent was to have the uint8_t val assigned the contents of the SPI receive register for each loop. The variable contents are used to drive a for-loop that continues looking for a 0x7E for 300 cycles.

Code: [Select]
#ifdef DEBUG
     usb.println(val,HEX);
#endif


My apologies, at the beginning of my code I #define Serial as usb...to save keystrokes and to help me keep up with the various serial outputs of the MEGA.
Title: Re: Xbee PRO S3B in API mode, inconsistent communication.
Post by: PaulS on Apr 24, 2019, 04:24 pm
Quote
where a zero is "transferred" to the device
To what device? The XBee is NOT an SPI device. Unless you have some non-standard XBee, in which case you need to provide a link to it.
Title: Re: Xbee PRO S3B in API mode, inconsistent communication.
Post by: agmotes on Apr 25, 2019, 04:47 pm
Once again, my apologies. I didn't realize that SPI was not a standard xbee interface. I've only worked with this type of xbee.

I'm using an Xbee Pro 900HP (S3B)

https://www.digi.com/products/embedded-systems/rf-modules/sub-1-ghz-modules/xbee-pro-900hp (https://www.digi.com/products/embedded-systems/rf-modules/sub-1-ghz-modules/xbee-pro-900hp)