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 CCS Technical Support

CCS PIC18F4520 Dev Kit + Xbee = problems

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



Joined: 09 Mar 2009
Posts: 4

View user's profile Send private message

CCS PIC18F4520 Dev Kit + Xbee = problems
PostPosted: Tue Mar 10, 2009 4:54 pm     Reply with quote

Currently I am trying to test out my 1mW Chip Antennae Xbee Transmitters with my PIC18F4520 dev kit, and I'm running into issues. As you might know, I cannot use the built in C6/C7 hardware UART pins as they are tied to a Max232 chip already, and don't have any pins I can tap them from. I have a logic level converter from 5 to 3.3 which is used on the xbee pins.

So what I am trying to do is:
Use C6/C7 as my hyper terminal to computer
use A1/A2 as the UART to XBEE
Send "+++" to the zigbee to enter into command mode, and receive "OK" back. I currently have the output from the zigbee on an Oscilloscope, and I'm checking for anything back.

Here's my code:

Code:
#include <18f4520.h>
#device ICD=TRUE
#fuses HS,NOLVP,NOWDT
#use delay(clock=20000000)
#use rs232 (baud=9600, STREAM=TERM, xmit=PIN_C6, rcv=PIN_C7)
#use rs232 (baud=9600, STREAM=XBEE, xmit =PIN_A2, rcv=PIN_A1,ERRORS,FORCE_SW,parity=N,bits=8) //A1 goes to TX0, A2 goes to RX1
#include <stdlib.h>
#include <input.c>

#define GREEN_LED PIN_A5  //Define the pins
#define YELLOW_LED PIN_B4
#define RED_LED PIN_B5
#define PUSH_BUTTON PIN_A4

void main() {
      unsigned char buffer = 0; //buffer
      unsigned char recdata = 0;  // variable for taking in data
      setup_uart(9600, XBEE);
      fprintf(TERM,"\r\n Sending test bit");
      fprintf(XBEE,"X"); //send arbitrary data
      delay_ms(1000); //delay 1 second
      while(TRUE){
     
      fprintf(XBEE,"+");//AT Command init
      delay_ms(250);
      fprintf(XBEE,"+");
      delay_ms(250);
      fprintf(XBEE,"+");
      delay_ms(1000);
      }
}


Currently I'm getting nothing back. For those of you who have used Xbee before, can you please help?


Last edited by triskadecaepyon on Tue Mar 10, 2009 7:48 pm; edited 1 time in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Mar 10, 2009 5:00 pm     Reply with quote

Post a link to the data sheet and schematic of your XBee board.
triskadecaepyon



Joined: 09 Mar 2009
Posts: 4

View user's profile Send private message

PostPosted: Tue Mar 10, 2009 5:13 pm     Reply with quote

Semi datasheet:
http://www.ccsinfo.com/product_info.php?products_id=18F452kit

Semi schematic (more or less layout)
http://www.ccsinfo.com/pdfs/product_PDFs/4520_board.pdf
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Mar 10, 2009 6:29 pm     Reply with quote

Where is the spec sheet for this:
Quote:
series 1 Xbee Transmitters

I want to see the specs on the serial interface. Is it RS-232, or TTL,
or inverted TTL levels ? What's the baud rate, etc. ?
triskadecaepyon



Joined: 09 Mar 2009
Posts: 4

View user's profile Send private message

PostPosted: Tue Mar 10, 2009 7:40 pm     Reply with quote

PCM programmer wrote:
Where is the spec sheet for this:
Quote:
series 1 Xbee Transmitters

I want to see the specs on the serial interface. Is it RS-232, or TTL,
or inverted TTL levels ? What's the baud rate, etc. ?


Sorry about not being more specific:
http://www.sparkfun.com/commerce/product_info.php?products_id=8664

UART w/ baud 9600.
triskadecaepyon



Joined: 09 Mar 2009
Posts: 4

View user's profile Send private message

PostPosted: Wed Mar 11, 2009 4:33 pm     Reply with quote

anyone?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Mar 11, 2009 5:06 pm     Reply with quote

Quote:
setup_uart(9600, XBEE);

Don't use setup_uart() with a software UART. The CCS manual says:
Quote:
setup_uart( )
Availability: This function is only available on devices with a built in UART.

Delete the setup_uart() line.


Quote:
fprintf(XBEE,"X"); //send arbitrary data

Does the data sheet say to do this ?


Quote:
fprintf(XBEE,"+");//AT Command init
delay_ms(250);
fprintf(XBEE,"+");
delay_ms(250);
fprintf(XBEE,"+");
delay_ms(1000);

You have a 1 second delay after sending the init string. But, you're using
a software UART to receive the response. There is no hardware buffer
to receive a byte when the software UART is used. If the PIC is not
looking at the Rx pin when the byte comes in, it will miss the byte.
What if the XBee unit sends a response before the 1000 ms is done ?
You will miss the byte.

Also, you are looking on a scope for the response. What if you miss it ?
You have a while() loop, to repeat the test, but what if the XBee unit
doesn't repeat the response ? What if it only sends it once, and it goes
by so fast that you miss it on the oscilloscope ?

I think it would be better to run the test one time (get rid of the while
loop) after power-up. Then look closely on the scope after you flip the
power-on switch for the board. Or, get rid of the final 1000 ms delay
and add some code to read the "OK" response from the XBee unit.
partisan



Joined: 16 Jul 2014
Posts: 2

View user's profile Send private message

PostPosted: Thu Jul 17, 2014 3:36 pm     Reply with quote

Hello guys. My name is Isaac. How are you?

Sorry for interrupt your conversation, but i really need help.
Guys, I connected the pin TXD of DB9 to pin R1IN of MAXRS232N and the pin R1OUT of MAX to pin RB2 of PIC18F4550. I'm using a xbee PROS2 too. The xbee is connected to PIC to receive and send data to another xbee and it is connected like this picture:

I'm using this code:
Code:
#include <18f4550.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#FUSES NOWDT                                                                    //No Watch Dog Timer
#FUSES HS                                                                       //Crystal osc <= 4mhz for PCM/PCH , 3mhz to 10 mhz for PCD
#FUSES NOBROWNOUT                                                               //No brownout reset
#FUSES PUT                                                                      //Power Up Timer
#FUSES STVREN                                                                   //Stack full/underflow will cause reset
#FUSES NOLVP                                                                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O

#use delay(clock=20000000)                                                      // Define frequĂȘncia do cristal em 20Mhz
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=XBEE)
#use rs232(baud=9600,parity=N,rcv=PIN_B2,bits=8,stream=BALANCA)

char caracter;

void main() {                                                           // ds1307_init() exemplos PICC
   while(1) {
      fprintf(XBEE, "x");
      delay_ms(2000);
   }
}
 


Just a simple test, but i receive just "...............". I'm using XCTU terminal and the baud rate is right "9600". What can be?

Ps: I've test the same with arduino and works.

Thank you[/img]
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jul 17, 2014 4:07 pm     Reply with quote

If you are using the hardware UART (pin C7 = Rx) to connect to the Tx
pin on the XBee, your circuit will not work. The hardware UART requires
a CMOS-level signal, which means the high level must be at least 4.0v
for a PIC running at 5v. Your XBee can only put a 3.3v high level,
so it won't work. The PIC can not receive the data correctly.
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