pic to pic via xbee

Discussion about projects that used PIC Microcontroller, Hardware Interface, Programming Algorithm and etc......

pic to pic via xbee

Postby yeohsheng » Mon Oct 15, 2012 11:24 pm

hi all, i'm new here
i would like to know how to communication between pic to pic via xbee
here is the easy connection i made.
im using xbee starter kit for both xbee

pic18f4520 to xbee1
pin RC7 (RX receive) to xbee xbee1 TX
pin RC6 (TX transmit) to xbee1 RX

2nd pic18f4520 to xbee2
pin RC7 (RX receive) to xbee xbee2 TX
pin RC6 (TX transmit) to xbee2 RX

i have programmed one of the xbee to be coordinator, another as router, both using 9600 baud rate and AT mode.

i have tested pic to pic via wire UART, it has succeed.
i use interupt receive method.
i also tested xbee1 to xbee2 communication using x-ctu. whatever i type at xbee1 shows at xbee2. whatever i type at xbee2 shows at xbee1.
but when i replace the wire with xbee, the communication is not done.
i'm not sure whether the transmit of xbee or receive of xbee is succeed or not.
is there a need to convert uart of pic voltage from 5v to 3.3v before connect to xbee uart?
can anyone help?
yeohsheng
Freshie
 
Posts: 6
Joined: Mon Oct 15, 2012 11:16 pm

Re: pic to pic via xbee

Postby shahrul » Tue Oct 16, 2012 8:17 am

PIC connect to XBee no need to convert.
PIC RX connect direct to XBee TX, PIC TX connect through 100 ohm to XBee RX.
User avatar
shahrul
Professional
 
Posts: 812
Joined: Sat May 16, 2009 9:54 pm
Location: Selangor

Re: pic to pic via xbee

Postby robosang » Tue Oct 16, 2012 11:05 am

How about PIC to computer? Is the baudrate correct?
robosang
Expert
 
Posts: 1239
Joined: Wed Jun 10, 2009 5:37 pm

Re: pic to pic via xbee

Postby yeohsheng » Tue Oct 16, 2012 12:47 pm

i believe it is correct. anyways, i post the code i using now just in case.
is there any ways to check or debug? i'm losing my way here. i followed the 100ohms idea, but still not working.
is it possible that i use x-ctu to check whether the xbee receive anythings from pic? if xbee1 receive, xbee2 should receive too, right?
Spoiler: show
#include <p18f4520.h>
#include <delays.h>

#pragma config OSC = HS
#pragma config WDT = OFF
#pragma config LVP = OFF
#pragma config PWRT = ON
#pragma config PBADEN = OFF

#define Fosc 20000000 //20M
#define BaudRate 9600
#define TRIS_TX TRISCbits.TRISC6
#define TRIS_RX TRISCbits.TRISC7

#pragma interrupt isr
#pragma code high_vector = 0x08
void dummy(void)
{ _asm GOTO isr _endasm }
#pragma code

unsigned char data;

void isr(void)
{
data = RCREG;
//PIR1bits.RCIF = 0;
if (data == 'C')
{PORTBbits.RB7 ^= 1;}

Delay10KTCYx(50);
}


void main(void)
{
//initialize UART
//unsigned int n;
//config BaudRate
TXSTAbits.BRGH = 1; //high Speed
BAUDCONbits.BRG16 = 0; //8 bits BaudRate Generator

//n = ((Fosc/BaudRate)>>4)-1; //>>4 = /4
//BaudRate input
SPBRG = 129; //0b10000001;
//SPBRGH = n>>8;

TXSTAbits.SYNC = 0; //Asynchronous mode
RCSTAbits.SPEN = 1; //Enable Serial Port/UART

TRIS_TX = 1;
TRIS_RX = 1;
TRISB = 0x0F;
PORTB = 0;

TXSTAbits.TXEN = 1; //enable transmition
RCSTAbits.CREN = 1; //enable receive

//Intrerrupt

PIR1bits.RCIF = 0;
PIE1bits.RCIE = 1; //enable receive interrupt
INTCONbits.GIE = 1;
INTCONbits.PEIE = 1;

while(1)
{
if (PORTBbits.RB0 == 0)
{
while(!TXSTAbits.TRMT);
TXREG ='C';
data = 0;
Delay10KTCYx(200);
} //while(!PIR1bits.RCIF);

}


}
yeohsheng
Freshie
 
Posts: 6
Joined: Mon Oct 15, 2012 11:16 pm

Re: pic to pic via xbee

Postby shahrul » Tue Oct 16, 2012 1:06 pm

yeohsheng WROTE:i believe it is correct. anyways, i post the code i using now just in case.
is there any ways to check or debug? i'm losing my way here. i followed the 100ohms idea, but still not working.
is it possible that i use x-ctu to check whether the xbee receive anythings from pic? if xbee1 receive, xbee2 should receive too, right?

I realize, you don't need 100 ohm since you use xbee starter kit, but I use only xbee module.
Wired connection PIC to PIC is working.

So, you try XBee + PIC transmit to XBee + Computer (Hyperterminal or VB). Like this XBee Lesson.
User avatar
shahrul
Professional
 
Posts: 812
Joined: Sat May 16, 2009 9:54 pm
Location: Selangor

Re: pic to pic via xbee

Postby yeohsheng » Tue Oct 16, 2012 1:43 pm

can i just use x-ctu to monitor?
since im using xbee starter kit, so i should be able to monitor from terminal. but i connected both xbee to my pc through xbee starter kit, i tried use the pic to transmit data, i didnt see any changes at the terminal.
yeohsheng
Freshie
 
Posts: 6
Joined: Mon Oct 15, 2012 11:16 pm

Re: pic to pic via xbee

Postby robosang » Tue Oct 16, 2012 9:49 pm

Cannot see the code you shared, but let's make it simple.

Program your PIC to send a single character every let say 100ms? You should be getting something at computer.

Yes, use the X-CTU to monitor it. Connect a SKXBee to PC via USB, another SKXBee to your PIC as you description.

Again, it always good to share the hardware setup, the actual hardware photo. Many cases are due to wrong hardware setup.
robosang
Expert
 
Posts: 1239
Joined: Wed Jun 10, 2009 5:37 pm

Re: pic to pic via xbee

Postby yeohsheng » Tue Oct 16, 2012 10:32 pm

the code i shared in spoiler, maybe thats why you didnt saw them.
i will upload the hardware pic tmr
yeohsheng
Freshie
 
Posts: 6
Joined: Mon Oct 15, 2012 11:16 pm

Re: pic to pic via xbee

Postby yeohsheng » Wed Oct 17, 2012 9:04 pm

one question is it normal that the rx and tx of xbee is remain high? even there is no transmit or receiving. by rx and tx i means the xbee starter kit tx and rx output pin. not the direct DI or DO pin of xbee module
yeohsheng
Freshie
 
Posts: 6
Joined: Mon Oct 15, 2012 11:16 pm

Re: pic to pic via xbee

Postby yeohsheng » Fri Oct 19, 2012 9:32 pm

anyways thx everyone who tried to help. i have succeed.
i found out the problem is my xbee starter kit. the rx tx output pin seems to have problem. so i take out the xbee then connect using breadboard, then it works like charm. xD
one more things, for RX and TX there is no need to use 100ohms. it works in my case
now i move on to API mode. as i need the mesh connection
yeohsheng
Freshie
 
Posts: 6
Joined: Mon Oct 15, 2012 11:16 pm

Next

Return to PIC Microcontroller

Who is online

Users browsing this forum: No registered users and 2 guests

cron