PDA

View Full Version : XBee API mode program examples



Ron Czapala
03-01-2010, 07:56 AM
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 (http://forums.parallax.com/member.php?u=42363)'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

Kevin SkyMoCo
03-04-2010, 09:23 AM
Hey, you beat me to it. :) I've attached my subroutines for sending and receiving messages.

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.

Ron Czapala
03-04-2010, 09:44 AM
Kevin,
· 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.

Kevin SkyMoCo
03-04-2010, 11:51 AM
I'm using a BS2e on the receiving end, I set the baud rate down to 2400 baud and am using the RTS pin 6. I haven't see any dropped packets, but then I haven't specifically watched for that. I thought the serin either gets the whole deal or it doesn't.

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.

Ron Czapala
03-04-2010, 08:08 PM
Kevin,

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.

Kevin SkyMoCo
03-05-2010, 08:13 AM
Ah, this is what I use to do that kind of thing as I had the same issue as you did. It seems to only work well whenl the data is in small bursts of fixed size.

Ron Czapala
03-07-2010, 04:21 AM
Kevin,

· 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!!!!·· http://forums.parallax.com/images/smilies/roll.gif·

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

Kevin SkyMoCo
03-07-2010, 01:44 PM
Sorry about that. I can still count the number of stamp programs I have written using only my fingers and toes.

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.

Ron Czapala
03-09-2010, 04:23 AM
Reading XBee parms in API MODE WORKS!!

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.