XBee API mode program examples
Ron Czapala
Posts: 2,418
As an addendum to this XBee·thread: http://forums.parallax.com/showthread.php?p=879115
I have created program examples to transmit and receive a WORD value between two XBees using API mode (AP=2).
I started·with Kevin SkyMoCo's code excerpt in the above thread...
Note: Even though they use operartion mode which utilizes Escape Characters, I did not need to escape any of the data bytes.
Sending character strings·could be tricky due to the limited memory of the BS2...
Post Edited (ronczap) : 3/1/2010 1:01:04 AM GMT
I have created program examples to transmit and receive a WORD value between two XBees using API mode (AP=2).
I started·with Kevin SkyMoCo's code excerpt in the above thread...
Note: Even though they use operartion mode which utilizes Escape Characters, I did not need to escape any of the data bytes.
Sending character strings·could be tricky due to the limited memory of the BS2...
Post Edited (ronczap) : 3/1/2010 1:01:04 AM GMT
Comments
I've found it best to just pass fixed length messages. In this case 1 type byte and 4 data bytes. I don't think the length matters that much so you could do more. I just make sure my data is outside the bytes that you have to escape so I don't have to deal with that or computing the amount of data to read.
Works for me, your mileage may vary..
If you have any questions, just ask and I'll try and answer.
· I tried using the AT cmd (0x08) and response structures (0x88)·and got flaky results (dropped bytes).
Using WAIT,SKIP and STR modifiers in the SERIN command seem to cause problems using the BS2 - might do better at slower baud rates. A BS2P stamp did a little better.
Reading various XBee parameters returns data of varying lengths depending - handling that in basic could get tough.
I think other microcontrollers and languages might work better with the API mode.
Hmm, I'll have to try zeroing out my data before I do the rx and then doing a exit if I still have zero's after my packet comes in. Maybe let that run for a day or so.
I probably wasn't clear wehn I talked about losing data. It wasn't being lost when sending data between two XBees, it was lost when getting a response (API indicator 0x88) from the transceiver after issuing a AT command (API indicator 0x08) to return a parameter value (e.g. DL or MY).
I have attached the code I was experimenting with. The commented code at the bottom where I was trying to use a byte array or using WAIT in the serin command was where bytes were being dropped.
· I could not get your code to work on a BS2 (it worked on a BS2p). I·tried changing the XBee Interface Data Rate to 2400 (ATDB 1) and it still wouldn't fly.
· I goofed!· I didn't notice that you had the baud setting hardcoded to 813 in the GetResponse subroutine...
I tweaked the code to set the baud value·based on the type of stamp.
Works for me now!!!!·· ·
I played around until I found that·a solution·for 8-bit and 16-bit return values. I use the HEX conversion formatter on the SERIN and DEC or HEX2/HEX4 on the debug command.
Post Edited (ronczap) : 3/6/2010 9:31:31 PM GMT
The code is not that well commented as I never really expected to share it... I've been testing on and off for a couple days and as long you're being reasonable and don't try and send too much data (like a couple packets per second) you don't lose any packets and life's good.
I found a trick that allowed me to sucessfully return 16-bit and 32-bit XBee parameters using API MODE.
Using the XBee Queue Parameter AT command (0x09) followed by the regular AT command (0x08).
Using·just the 0x08 command by itself seem to only work sporadically.
The attached source code works on my BS2 and BS2P stamps at 9600bps.
I set DL to CEDDFEFF and MY to 1084 while initializing the XBee in·transparent mode and returned the values in API MODE.