Interfacing xbee with PIC microcontroller using MikroC




In this tutorial, I will show how to interface an xbee module with PIC microcontroller.Here MikroC Pro for PIC compiler is used to write the code. Xbee modules communicates with host devices using serial communication.Most of the PIC microcontroller have UART module to support serial communication.

First of all we have to understand the two operating mode of xbee.

  • Transparent Mode
  • API Mode

Interfacing xbee with PIC microcontroller using MikroCInterfacing xbee in Transparent Mode

In transparent mode two xbee module makes just simple bridge of  serial communication.This is like just remove the wire of serial port and place two xbee module.In this mode if you send ‘A’ then another module will receive ‘A’.To send data write this code

void main() {
UART1_Init(9600);   // Initialize UART module at 9600 bps
Delay_ms(100);      // Wait for UART module to stabilize
UART1_Write(‘A’);
}
To receive this data on the other side write this code
char receive;
void main() {
UART1_Init(9600);  // Initialize UART module at 9600 bps
Delay_ms(100);   //Wait for UART module to stabilize
// If data is ready, read it:
if (UART1_Data_Ready() == 1)

{receive = UART1_Read();}}

Interfacing xbee in API Mode

API mode is main thing of a xbee module.You can make mesh networking,use of analog to digital pins(IO pins).In this mode all communications take place as structured data frame.Here some examples of data frame are shown:

AT Commands

The following image shows the API frame exchange that takes place at the UART when sending an AT command request to read or set a module parameter. The response can be disabled by setting the frame ID to 0 in the request.

Interfacing xbee with PIC microcontroller using MikroC schematicTransmitting and Receiving RF Data

The following image shows the API exchanges that take place at the UART when sending RF data to another device. The transmit status frame is always sent at the end of a data transmission unless the frame ID is set to 0 in the transmit request. If the packet cannot be delivered to the destination, the transmit status frame will indicate the cause of failure. The received data frame (0x90 or 0x91) is set by the AP command.you can get all the frames structures in datasheet.So we don’t proceed to explain each data frame.Our concern is to send these frames or receive these frames using PIC microcontroller.

 

For more detail: Interfacing xbee with PIC microcontroller using MikroC




Current Project / Post can also be found using:

  • interfacing zigbee with pic16f877a microcontroller
  • xbee with microcontroller
  • can zigbee interface to pic
  • xbee with pic microcontroller

Leave a Comment

*
= 5 + 7

Read previous post:
Getting started with PIC18F Microcontrollers

After writing quite a bit of experimental tutorials on PIC16F series of microcontrollers, I thought of moving forward to the...

Close
Scroll to top