XBee and PIC16F628A communication

Bluetooth, XBee, RF......

XBee and PIC16F628A communication

Postby alex_86 » Thu Feb 17, 2011 11:01 am

Hi
I have managed to conenct my XBee to my computer and have tested it out with a friend of mine. We have managed to send and receive data by using the X-CTU software provided. This is to show that the seetings for the XBee (such as source and destination address) are alright.
But when I try to send a data from my microcontroller (PIC) to the computer via the XBees, I am not able to get any data from the X-CTU "Terminal" tab.

I am using the correct method to see the incoming data??

Please advise.
Thanks
alex_86
Newbie
 
Posts: 13
Joined: Sun Jan 23, 2011 3:09 pm

Re: XBee and PIC16F628A communication

Postby yonghui » Thu Feb 17, 2011 12:06 pm

hi,
cant really understand the question.

why connecting microcontroller display xtcu?
did u mean tat u send data from microcontroller to pc by using xbee? then view the data from xctu?
the xbee is powering up properly with 3.3V?


regards,
yh
thanks&regards,
yh
yonghui
Moderator
 
Posts: 732
Joined: Mon Sep 28, 2009 3:27 pm

Re: XBee and PIC16F628A communication

Postby alex_86 » Fri Feb 18, 2011 8:24 am

Sorry. Let me rephrase.
I have two sections. Say "A" and "B".
"A" has a XBee conencted to the computer via a MAX232 - RS232 connection. This section works ok.
"B" is the other section that is connected to the PIC.

The problem is, when I send a data from "A" to "B" using the X-CTU software, the data is transmitted (LED at XBee lights up to indicate transmission). But when I program the PIC at the "B" section to send some characters to "A", it is not able to send anything (No LED lighting up). Occasionally, I will get a full stop "." when I power up my "B" section.

I use 3.3V to power up my PIC so that I can directly connect the TX and RX to and from the XBee at "B".

Is my problem caused by programming error or hardware error?
alex_86
Newbie
 
Posts: 13
Joined: Sun Jan 23, 2011 3:09 pm

Re: XBee and PIC16F628A communication

Postby yonghui » Sat Feb 19, 2011 9:38 pm

hi,

hi, pls check to make sure that PIC16F628 can run at voltage of 3.3V. if the PIC can run on 5V only, then means that the PIC is not running at all.
the xbee Uart baudrate is correct onot?

regards,
yh
thanks&regards,
yh
yonghui
Moderator
 
Posts: 732
Joined: Mon Sep 28, 2009 3:27 pm

Re: XBee and PIC16F628A communication

Postby alex_86 » Sat Feb 19, 2011 9:48 pm

Yes. The PIC can operate from 2.0v to 5.5v. The baud rate is set at 9600 for both the XBee and the PIC.

Currently, I am not able to send any data at all from my PIC to the XBee. I have the usart header and c file all included, compiled and programmed into the PIC. The thing is that when i write this code

putch('a');

or even

putch(0x61);

I am not able to receive anything. Occasionally, when I turn on and off my circuit, a full stop will be sent over.
alex_86
Newbie
 
Posts: 13
Joined: Sun Jan 23, 2011 3:09 pm

Re: XBee and PIC16F628A communication

Postby alex_86 » Sat Feb 19, 2011 9:55 pm

Sorry, when I turn OFF and ON****
alex_86
Newbie
 
Posts: 13
Joined: Sun Jan 23, 2011 3:09 pm

Re: XBee and PIC16F628A communication

Postby aurora » Sun Feb 20, 2011 1:14 am

Can you confirm if your uC is sending the right data? Like connecting your uC direct your your MAX232, and able to receive the character?

If i remember correctly, XBee take a few seconds (like 1-2s) to pair before sending/receiving is possible. By right, you shouldn't be seeing any character (in this case, the dot) so soon, could be a glitch or power spike when you switch on. You can try click on "show hex" in Terminal window. It will show you the hex for the dot. It's probably random.
aurora
Discoverer
 
Posts: 126
Joined: Sun Jun 07, 2009 4:52 pm

Re: XBee and PIC16F628A communication

Postby ABSF » Sun Feb 20, 2011 7:14 am

How is your connections between your PIC and the XBee on B section?

Are you using RB1/RX, RB2/TX and Ground 3 wires connection to XBee? What xtal freq. are you using and how is your initialization code for '628A? Did you try communicating at a lower baud rate like 1200 or 2400?

Allen
The next war will determine NOT who is right BUT what is left.
User avatar
ABSF
Professional
 
Posts: 810
Joined: Wed Nov 10, 2010 9:32 am
Location: E Malaysia

Re: XBee and PIC16F628A communication

Postby shiyan » Sun Feb 20, 2011 12:02 pm

I would strongly recommend what is being shown by aurora. Makesure your PIC is working perfectly from the UART point of view. Try connecting your PIC to computer and look what is being send from the PIC.
User avatar
shiyan
Amateur
 
Posts: 189
Joined: Wed Jun 09, 2010 10:59 am

Re: XBee and PIC16F628A communication

Postby alex_86 » Sun Feb 20, 2011 2:02 pm

aurora WROTE:Can you confirm if your uC is sending the right data? Like connecting your uC direct your your MAX232, and able to receive the character?

If i remember correctly, XBee take a few seconds (like 1-2s) to pair before sending/receiving is possible. By right, you shouldn't be seeing any character (in this case, the dot) so soon, could be a glitch or power spike when you switch on. You can try click on "show hex" in Terminal window. It will show you the hex for the dot. It's probably random.


Yes. I did connect the max232 directly to the PIC. The full stop is indeed a random hex value as shown in the image.

This is the code that i used. I know there may be redundant codes, but I'm leaving it there for now.
CODE: SELECT_ALL_CODE
#include <16F628A.h>
#fuses INTRC_IO, NOLVP, NOWDT, PUT, BROWNOUT
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_B2, rcv=PIN_B1, INVERT, ERRORS)
#include <htc.h>
#include <stdio.h>
#include "usart.h"
#include <stdlib.h>
#include <string.h>
#byte PORTB = 6 /*map ports */
#byte PORTA = 5
//#include <i2c.h>
#define _XTAL_FREQ 4000000
__CONFIG (0x2134);      //0x - hex ;; 0b - binary
_LVP_OFF;
BAUD9600;

int main ()
{
CMCON = 7;
char a,b,x,y;
unsigned char j;
int i;
long code_d0, code_d1;

long c_d0[6];
long c_d1[6];
//char *file = "C:\\file.txt";

   while (1) {         // infinity loop..for;;

   //codes
   TRISA = 0xff;         //configure all a ports as inputs
   TRISB = 0x00;         //configure all b ports as outputs
   
   //SETUP_UART(FALSE);
   
   x = RA0;
   y = RA1;
   b = ((0b00001111 || RA0)||(0b1111));
   PORTB = x;
//   code_d0=RA0;
//   code_d1=RA1;

   putch(0x48);
   putch(0x45);
   putch(0x4C);
   putch(0x4C);
   putch(0x4F);
   
   
   putch(getch);
   //__delay_ms(1000);
   a = getch;

   if(a == '1'){
      RB4 = 0b00000001;
      RB5 = 0b00000000;
      RB6 = 0b00000000;
      RB7 = 0b00000000;
   }
   else if (a == '2'){
      RB4 = 0b00000000;
      RB5 = 0b00000001;
      RB6 = 0b00000000;
      RB7 = 0b00000000;   
   }
}
}

Sorry for the length. Practically, when i send 1 the led should light up. But instead, I get the output as shown.
Blue is the code I type, and red is the received data.
Attachments
X-CTU  [COM4] 2.jpg
alex_86
Newbie
 
Posts: 13
Joined: Sun Jan 23, 2011 3:09 pm

Next

Return to Wireless Device

Who is online

Users browsing this forum: No registered users and 39 guests

cron