Thursday, August 21, 2014
XBee API Frame Data transmit
When you want to use XBee ADC pins you must have to use API format here.In my case both coordinator and router was configured in API form. In API format data is sent or using specific data frame structure.For example ADC data sent to coordinator from router looks like
~.......@R..].........F|~.......@R..].........F|~.......@R..Note the repeating tilde (~) character. This is the ASCII equivalent of
].........E}~.. .....@R..].........E}~.......@R..].........
F|~.......@R..].........F|~..... ..@R..].........E}~.......@R..
].........E}~.......@R..].........E}~.......@ R..].........
F|~.......@R..].........E}~.......@R..].........F|~.......@R..
].........E}~.......@R..].........E}~.......@R..].........F|
0x7E, the start byte, and is a clear indication that rather than seeing
garbage, you are seeing good data being delivered in API mode. Switch
into viewing hex to see the API frame contents properly.
Data frame forms an API-specific structure as follows:
Router XBee was sending data by using this frame.Actually we some specific frame structure and each structure has distinct function .See the list of available Frames you may need:
From this list you have to decide which Frame you will use as your requirement and function of the Frame.
As I need to transmit data from one module to another ZigBee Transmit Request with Frame ID 0x10 is the appropriate Frame.Let’s see the structure of this frame,
our frame begins with a start byte, length bytes, a frame type (in this case 0x10,
indicating the ZigBee Transmit Request format), and a frame ID. This preamble is
followed by addressing information that we’ll look at in detail, and then by the data
payload itself. The frame concludes as always with a single-byte checksum.
Now I will give short explanation of data field we have to change in frame.
64-bit destination address
These eight bytes indicate the unique-in-the-world destination address for this trans-mission, for example 0x0013A200400A0127.In my case I want to send data to router so I change it 0x0013A20040A9CF30(Serial no. of my router XBee).If you want to reach the network coordinator, you can set this address to
0x0000000000000000 (that’s 16 zeros) and it will be routed automatically. To send a
broadcast message that is delivered to all nodes on the network, set the 64-bit desti-nation address to 0x000000000000FFFF.
RF data
At long last we come to the main point. The RF data is the data we wanted to sendin the first place! It is the meat of our protocol sandwich (or the tasty eggplant, in case
meat isn’t your thing). Assemble your data into a string of bytes. On many small networks you can usually put up to 84 bytes in your payload transmission. Of course, if
you keep your individual data transmissions small, you won’t need to worry about this
limit.
I just put here 0x13(one byte data).
Checksum
The very last byte of the frame is always a checksum. The checksum is calculated based on all the bytes that came before it. It’s a simple sum of all the bytes that made up the frame,used at the receiving end to check and see if there was a transmission error. The calculation is regular arithmetic,designed to be extremely efficient for computers to process.Here’s the checksum formula, as stated in the official documentation:You can take help from DIGI API Frame Maker.
• To calculate: Not including frame delimiters and length, add all
bytes, keeping only the lowest 8 bits of the result, and subtract the
result from 0xFF.
• To verify: Add all bytes (include checksum, but not the delimiter
and length bytes). If the checksum is correct, the sum will equal
0xFF.
Ok, now we will turn to do something real to do. My coordinator XBee and router XBee are connected to two different PCs with Usb to serial board.From X-CTU terminal Click Assemble Packet button and put
7E 00 0F 10 01 00 13 A2 00 40 A9 CF 30 FF FC 00 00 13 43Don’t forget to select HEX shown in image.
Then send this data.As my router was connected to PC with X-CTU hence terminal shows
Well done!!! I sent 1 byte data to Router.You can send more data using this technique.Suppose you rave more routers and end devices and you need to send data to a specific device so just change 64-bit destination address according to that device.
You can also send data from router to end device and vice versa.
I hope that this post will helpful for you to work with building wireless sensor network.
Feel free to comment or contact with me to share your idea or problem.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment