PIC32 and XBee

I have a pic32 Starter Kit with i/o expansion board. I am trying to set up uart communication between the starter kit and my pc using 2 XBee Pro 50mW Series 2.5 Chip Antenna(2.4GHz XBee XBP24-BCIT-004 ). I have the Starter Kit connected to the first XBee module (XBee1) which is mounted in a breakout board on my solderless breadboard. XBee1 is powered by a 3.3V regulated power supply on the breadboard. The second XBee module (XBee2) is mounted on an XBee USB Explorer that is connected by USB to my pc. The connections between XBee1 and the Starter Kit(SK) are as follows:

  • SK UART2 RX to XBee1 DOut (with a 15k ohm resistor in series)
  • SK UART2 TX to XBee1 Din (with a 15k ohm resistor in series)
  • LEDs from the XBee1 power pin and associate pin to ground (with resistors in series)
  • 3.3V from the breadboard regulated power supply to XBee1 Vcc
  • XBee1 GND to breadboard regulated power supply ground
  • common ground between breadboard regulated power supply, XBee1, and Starter Kit

I do not have U2CTS or U2RTS connected to anything.

I tested this configuration with an Arduino I had laying around and was able to send and receive data between XBee1 and XBee2 with no problem, so I know that the XBee modules are configured correctly. The XBees are set to 9600 baud, 8-N-1, no flow control.

When I power everything up, the LEDs turn on and the associate LED begins to blink as it should. However, I am not receiving any data from the Starter Kit via UART.

Do I have to use U2CTS and U2RTS?

Do I have to configure the UART2 RX and TX pins in code in a way other than I have?

I have written a very simple bit of code to test this set up. If anyone can think of what I am doing wrong I would be very appreciative.


 // Configuration Bit settings //
 SYSCLK = 80 MHz (8MHz Crystal/ FPLLIDIV * FPLLMUL / FPLLODIV) // PBCLK = 40 MHz // Primary Osc w/PLL (XT+,HS+,EC+PLL) // WDT OFF
 #pragma config FPLLMUL = MUL_20, FPLLIDIV = DIV_2, FPLLODIV = DIV_1, FWDTEN = OFF #pragma config POSCMOD = HS, FNOSC = PRIPLL, FPBDIV = DIV_2 //Fpb=40,000,000 
int main(void) { SYSTEMConfigPerformance(80000000L); 

long i;
 // Open UART2 with Receive and Transmitter enable. 

OpenUART2(UART_EN, UART_RX_ENABLE | UART_TX_ENABLE, 259); //(Fpb/16/9600)-1=259
 while(1) { for(i=0; i<2000000; i++); // put a delay
 //send the letter "a" over UART2 

"); };

return 0; }

Hardware looks ok, especially if you have tested with an Arduino.
I would suggest its in the software. I see that you are not using any interrupts. I would be tempted to ditch microchips uart routines and set the registers yourself, so you are sure that everything is getting set. Then use interrupts for any receive stuff.
Also, I’m not sure what is receiving or what is transmitting.
Do you mean you transmit from the PIC and you see nothing coming out of its uart, or nothing coming out of the xbee explorer??
If nothing is coming out of the uart (I assume you have checked with a scope?) then it is a definite problem with the software. If nothing is being transmitted, are you sure you are transmitting correctly? API mode, etc.


To ensure that the code in the PIC is correct, remove the XBees from the link and hardware the PIC to an RS232 translator (or to the FTDI breakout without the XBee installed). Once you have the PIC sending and receiving to the PC put the XBees back in.

thanks for the suggestions. It turns out that the problem was in the code. I had to add the following and then it worked fine:

SYSTEMConfigPerformance(80000000L); OSCSetPBDIV(OSC_PB_DIV_2);

I also removed the resistors between the PIC32 and the XBEE after reading the XBEE datasheet more closely. It says to connect the XBEE pins directly to the microcontroller.

thanks again!