Forums

It is currently Wed Jun 19, 2013 6:25 pm

All times are UTC




Post new topic Reply to topic  [ 36 posts ]  Go to page 1, 2, 3  Next
Author Message
 Post subject: Xbee Wireless Interface
PostPosted: Fri Jun 17, 2011 6:28 pm 
Offline
PyroElectro Admin

Joined: Mon Nov 12, 2007 9:24 pm
Posts: 942
Location: Earth
Xbee Wireless Interface Tutorial

Quote:
This PyroElectro tutorial shows you how to use two PICs and two Xbee modules to create a wireless interface between the two microcontrollers. The Xbee modules allow for flexible and reliable wireless communication with many configuration options.



Questions & Comments?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 21, 2011 3:37 pm 
Offline
Newbie Pyro

Joined: Tue Sep 20, 2011 11:43 pm
Posts: 12
very helpful thanks


Top
 Profile  
 
PostPosted: Thu Nov 24, 2011 7:59 pm 
Offline
Newbie Pyro

Joined: Thu Nov 24, 2011 7:51 pm
Posts: 9
Hello,

I built the Xbee interface using PIC18F4550 instead of using PIC18F4250. When I try and load the Hex file on to the pics I get an error saying:

Writing program memory successful
mismatch in 32-byte chunk at 0x00000000:
File: ################5cef08f01200####################################
Device:2cef04f01200120004ef08f012000000ffffffffffffffff0cef08f012000100
Program memory contains errors!

I am using FSUSB to program the PIC, this is the RX code. I changed the #include <p18f4250.h> to #include <p18f4550.h>.

Any ideas?


Top
 Profile  
 
PostPosted: Thu Nov 24, 2011 9:09 pm 
Offline
PyroElectro Admin

Joined: Mon Nov 12, 2007 9:24 pm
Posts: 942
Location: Earth
Hi,

This sounds like there's a problem with your programmer.

Does a simple program like an LED flasher work?

Code:
#include <p18f4550.h>
#include <delays.h>

void main(void){
TRISA = 0x00;
PORTA = 0x00;
     while(1){
          Delay10KTCYx( 250 );
          PORTA = 0xFF;
          Delay10KTCYx( 250 );
          PORTA = 0x00;
     }
}


If something like the program seen above, compiles and programs successfully onto the 4550, then either something in MPLAB is set incorrectly, or my software for the XBEE modules needs to be modified to be compatible with that version of the PIC.


Top
 Profile  
 
PostPosted: Fri Nov 25, 2011 3:49 pm 
Offline
Newbie Pyro

Joined: Thu Nov 24, 2011 7:51 pm
Posts: 9
The code you just give me complies and programs perfectly. I didnt think there was much of difference in using the 4550.


Top
 Profile  
 
PostPosted: Fri Nov 25, 2011 3:54 pm 
Offline
Newbie Pyro

Joined: Thu Nov 24, 2011 7:51 pm
Posts: 9
The transmitter code compiles and seems to load up fine. Its the Receiver code, it compiles fine but when I program it using FSUSB through the linux terminal it gives me the above error.


Top
 Profile  
 
PostPosted: Fri Nov 25, 2011 4:22 pm 
Offline
PyroElectro Admin

Joined: Mon Nov 12, 2007 9:24 pm
Posts: 942
Location: Earth
Quote:
The code you just give me complies and programs perfectly. I didnt think there was much of difference in using the 4550.


There really isn't, I just can't imagine why MPLAB would spit that out. It's a problem I've never run into.

Quote:
The transmitter code compiles and seems to load up fine. Its the Receiver code, it compiles fine but when I program it using FSUSB through the linux terminal it gives me the above error.


My only guess is that it's a programmer problem. Maybe try programming on a windoze box?

Another option would be to re-write the code piece by piece, compiling and downloading to the PIC until you get that similar error again. Then you'll know what part of the code might be causing the problem, since other programs seem to download fine.

::EDIT::

Apparently the FSUSB programmer relies on a bootloader to program the PIC which will have re-mapped your interrupt vectors. My bet is if you deleted all of the interrupt related code for the receiver, compiled and downloaded it to the PIC it would work just fine.

You'll have to lookup the new address for the High and Low Interrupt so that you can point it to the InterruptHandlerHigh() function.


Top
 Profile  
 
PostPosted: Fri Nov 25, 2011 7:00 pm 
Offline
Newbie Pyro

Joined: Thu Nov 24, 2011 7:51 pm
Posts: 9
Ok, so deleted the handler sections. and I still compiled and programmed. I am sure you are right about the Bootloader. I am lost on a work around for this.


Top
 Profile  
 
PostPosted: Fri Nov 25, 2011 7:18 pm 
Offline
PyroElectro Admin

Joined: Mon Nov 12, 2007 9:24 pm
Posts: 942
Location: Earth
Dustinjan10 wrote:
Ok, so deleted the handler sections. and I still compiled and programmed. I am sure you are right about the Bootloader. I am lost on a work around for this.


I took a look at the User Guide for the FSUSB located here:
http://ww1.microchip.com/downloads/en/devicedoc/51526a.pdf
and I found the following:
Quote:
Remapped Vectors
Since the hardware reset and interrupt vectors lie within the boot area and cannot be
edited if the block is write-protected, they are remapped through software to the
nearest parallel location outside the boot block: 0x0800 for Reset, 0x0808 for the High
Priority Interrupt vector, and 0x0818 for the Low Priority vector. Remapping is simply a
GOTO instruction for interrupts. Users should note that an additional latency of two
instruction cycles is required to handle interrupt


My guess is that if you change the following section of the receiver code
FROM:
Code:
//**BEGIN INTERRUPT CONTROL**
#pragma code InterruptVectorHigh = 0x08      //interrupt pointer address (0x08 high priority)

TO:
Code:
//**BEGIN INTERRUPT CONTROL**
#pragma code InterruptVectorHigh = 0x808      //interrupt pointer address (0x08 high priority)


It should compile and download without any problem.


Top
 Profile  
 
PostPosted: Fri Nov 25, 2011 8:49 pm 
Offline
Newbie Pyro

Joined: Thu Nov 24, 2011 7:51 pm
Posts: 9
That did it. Thank you, your awesome.


Top
 Profile  
 
PostPosted: Tue Nov 29, 2011 8:41 pm 
Offline
Newbie Pyro

Joined: Thu Nov 24, 2011 7:51 pm
Posts: 9
I have another question for you, if you dont mind. Do I need to Configure my Xbee pros via the parallax usb adapter before this will work?


Top
 Profile  
 
PostPosted: Fri Dec 02, 2011 12:42 am 
Offline
PyroElectro Admin

Joined: Mon Nov 12, 2007 9:24 pm
Posts: 942
Location: Earth
Xbee modules come set with default values, double check the data sheet if you're unsure. The default value for serial communication TX/RX is 9600 baud. So if you send 9600 BPS baud rate serial data to the transmitter Xbee's DIN pin you'll see the exact same thing come out of the receiver Xbee's DOUT pin.


Top
 Profile  
 
PostPosted: Sat Dec 10, 2011 1:38 am 
Offline
Newbie Pyro

Joined: Thu Nov 24, 2011 7:51 pm
Posts: 9
Is there a way to do this without using interrupts?


Top
 Profile  
 
PostPosted: Sat Dec 10, 2011 4:06 am 
Offline
PyroElectro Admin

Joined: Mon Nov 12, 2007 9:24 pm
Posts: 942
Location: Earth
Dustinjan10 wrote:
Is there a way to do this without using interrupts?


Yes, but it wouldn't be very reliable because you would have to poll to check and see if the USART receiver buffer is ready/full. Depending on the timing you could potentially miss transmitted data.

However, if you still wanted to do it without interrupts then you would do everything in the main loop and included a forever while loop similar to this:

Code:
  while(1)
  {
    while(!DataRdyUSART());  //wait for data
    data = ReadUSART();      //read data
    ...         //Do
    ...         //Something
    ...         //Here
   }


Top
 Profile  
 
PostPosted: Sat Dec 10, 2011 7:38 pm 
Offline
Newbie Pyro

Joined: Thu Nov 24, 2011 7:51 pm
Posts: 9
This is what I have so far:

Transmitter:
while(BusyUSART())
{
WriteUSART("Test");
DelClks(48000000 * 0.5);
}

Receiver:
unsigned char data;

while(!DataRdyUSART);
{
data = ReadUSART();
DelClks(48000000 * 0.5);
LcdDspChar(data);
}

I have gotten something like this to work but when it is displayed on the lcd it is scrambled.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 36 posts ]  Go to page 1, 2, 3  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group