CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

XBee PIC18F4520

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
ilato88



Joined: 01 Aug 2010
Posts: 1

View user's profile Send private message

XBee PIC18F4520
PostPosted: Sun Aug 01, 2010 7:18 pm     Reply with quote

Hi i am new to using PIC microcontrollers and wireless modules. I have decided to use the XBee modules since it says that by default, out of the box they are serial port replacements to communications.

I am using the CCS compiler with the 2 PIC18F4520 running on 5V, 2 XBee 1mW modules on 3.3V. The goal is to establish a simple connection from one PIC to the other PIC using XBee.

The simple code works when the 2 PICS are connected to each other from the Transmit Pin and Receive Pin and works perfectly. My understanding is that instead of connecting the Transmit and Receive to each other I connect them to the XBee and the same code should communicate.

I have not gotten it to work using a variety of different configurations and have gotten a bit frustrated. The whole circuitry for both are running on the same supply right now, i have tried using resistors from the PIC Tx and Rx, as i have seen some configurations with them included. From my understanding if they are communicating PIC to PIC they should communicate PIC to XBee to XBee to PIC.



Here is the simple code i am testing.

The first code to PIC is to transmit:

Code:

/* pic2pic_transmit.c
The transmitter checks to see if PIN A0 is high or low.
If the  pin is high, the transmitter sends the signal 'a' to the receiver and
turns on an LED. If the pins is low, the transmitter sends the signal 'b'.
*/

#include <18f4520.h>
#fuses HS,NOLVP,NOWDT,NOPROTECT       
#use delay(clock=20000000)       // 20 MHz crystal on PCB
#use rs232(baud=9600, UART1)       


#include <stdlib.h>

#define LED_0 PIN_D0

void main() {
   while (TRUE) {
      if (input(PIN_A0)){
         output_high(LED_0);
         printf("a"); //sends signal a
       }
       else{
         output_low(LED_0);
         printf("b"); //sends signal b
       }
       
       }
   }


The second code is set on the other PIC to receive:

Code:



/* pic2pic_receive
The receiver checks the signal from the XBEE and if the signal is 'a', the receiver turns on an LED.
*/

#include <18f4520.h>
#fuses HS,NOLVP,NOWDT,NOPROTECT       
#use delay(clock=20000000)       // 20 MHz crystal on PCB
.
#use rs232(baud=9600, UART1)   

#define LED_0 PIN_D0

#include <stdlib.h>

char x;

void main() {
   while (TRUE) {
       if (kbhit()) {
         x = getc();
       }
       if (x=='a'){
         output_high(LED_0);
         
       }
       else{
         output_low(LED_0);
         
       }
   }
}



Thanks in advance for any help!
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

Re: XBee PIC18F4520
PostPosted: Sun Aug 01, 2010 10:23 pm     Reply with quote

ilato88 wrote:
The whole circuitry for both are running on the same supply right now...


Hopefully you mean everything is running from 3.3 volts. If you power a Xbee module from 5 volt you may destroy it.

They almost works out of the box. You have to configure each unit with its local address and the address of the target (remote) unit. Let's say you have two units, A and B. On A you will configure its address as 0 and the remote (B unit) as 1. Then on module B you will configure Module B's address as 1 and the remote unit as 0. Now anything you transmit on A will be received on B and visa versa.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group