1

I have used the Xbee API mode successfuly when communicating between two computers while they were attached to USB explorer (I send data and it is received). However when I try to do the same with the radios being attached to pic33 microcontroller, I'm getting strange results. Here is my setup:

A Xbee radio, router, attached with a PC And a Xbee radio, co-ordinator, attached with a pic33 microcontroller

The microcontroller sends broadcast data. Here is the API command:

7E 00 13 10 01 00 00 00 00 00 00 00 00 FF FE 00 00 48 65 6C 6C 6F FD

7E: Delimiter
00 13: Length
10 01: API frame type and frame ID
00 x 8 : Coordinator 64 bit address
FF FE: 16 bit network address
00 00: Options and braodcast radius
48 65 6C 6C 6F: Data (Hello)
FD: Checksum

The same command works perfectly with both radios hooked to PCs and results in the XCTU windows.

I have debugged the whole transmit code and its sending the command as it should. I checked the TXREG registers in online debugging with PICKIT3. But nothing is being received in the XCTU window.

I have played with different delays, tried continuous and single transmission and everything I can think of but I get absolutely nothing in the XCTU window. What I want to know is that is that what do I have to do to make it work?

Sam DeHaan
  • 10,246
  • 2
  • 40
  • 48
  • Are you sure, you properly configured your RS232 port in PIC? Does Xbee module responds for other requests? Like get status... etc.. – werewindle Apr 02 '12 at 16:41

2 Answers2

1

Chances are this is an electronics program and not a coding problem. The XBee will behave correctly if it is able to communicate with the PIC. You've got the following problem space:

1) Either your code is not transmitting the packet correctly (which you've debugged) or, 2) There is some problem in the electronic communications path between the PIC and the XBee

Here are some things to ask yourself and verify when connecting XBees to microcontrollers:

1) How are you connecting your XBee to your PIC? The XBee serial I/O is 3.3v. Ensure that the logic level of your PIC is also 3.3v

2) What baud rate are you setting your PIC to? What is your PIC's timing source? Is it is an internal oscillator, an RC or a crystal? Ensure that the timing value of the oscillator matches the datasheet to derive the expected baud rate.

3) Can you read from the XBee? If you send a packet from a module attached to a PC to the module attached to your PIC, what arrives at your micro? Are you able to receive the entire packet? Are there missing bytes? Are you receiving garbage (again, this may indicate a baud rate mismatch)?

4) Do you have hardware flow control enabled (XBee parameters D6 and D7)? If so, how have you connected those pins? Ensure that their logic levels are set correctly so the XBee is not permanently in a state of flow control and therefore preventing it from receiving the bytes from your PIC. You may want to disable flow control until you get basic communications working.

You may want to divide and conquer the hardware problem space by eliminating the XBee from the equation entirely and focus on ensuring that you're able to transmit serially as you expect. If you have a level shifter, you can attach it to your PIC and then attach your PIC to your PC. You can verify that you can read the message you are attempting to send from a PC terminal program. If you're lucky enough to have a logic analyzer, you can perform the same test without having to attach the logic analyzer.

Best of luck!

Jordan
  • 986
  • 9
  • 13
  • 1
    I'll also mention that it's easy to accidentally swap your Tx/Rx pins when connecting a microprocessor to the XBee. Make sure the PIC's transmit goes to the DIN pin of the XBee. – tomlogic Apr 03 '12 at 19:05
0

Digi has released xbee_ansic_library, an Open Source (MPL 2.0) library of ANSI C code for communicating with XBee modules in API mode. It supports POSIX (Linux, BSD, Mac OS X, Cygwin), Windows (MinGW/MSYS), DOS (OpenWatcom) and some embedded platforms.

While it doesn't support the PIC platform (yet), you might want to try writing the necessary glue code (mostly the serial routines) to use it on your hardware.

It's also useful for writing desktop apps to communicate with your embedded devices via the XStick or XBee USB adapters.

tomlogic
  • 11,489
  • 3
  • 33
  • 59