|
|
View previous topic :: View next topic |
Author |
Message |
wongchunyuan
Joined: 14 Jun 2012 Posts: 3
|
PIC18F4620 unable to transmit data to XBEE2(no output at tx) |
Posted: Thu Jun 14, 2012 12:28 am |
|
|
Hello Guys,
I am connecting two XBEE together,
XBEE1 and XBEE2, XBEE1 as coordinator and XBEE2 as router.
I tried to connect them using XCTU and they are able to communicate with each other.
Then, i remain the XBEE1(coordinator) connected via XCTU, and i connect XBEE2 to my PIC18F4620, connecting XBEE2's RX to PIC's TX and XBEE2's TX to PIC's RX.
Then i run the program as below:
Code: | #include <18F4620.h> // PIC18F4620 HEADER FILE
#include <stdlib.h>
#fuses HS,NOWDT,NOLVP,NOPROTECT // HIGH SPEED, NO WATCH DOG TIMER, NO LOW VOLTAGE PROGRAMMING
#use delay (clock=20M) // 20 MHZ CRYSTAL
#use rs232(baud=9600, UART1)
#define but1 PIN_A0
#define on PIN_B4
set_tris_a(0xFF); // SET ALL PORT A AS INPUT PORT
output_a(0xFF); // RESET PORT A
set_tris_b(0x00); // SET ALL PORT B AS OUTPUT PORT
output_b(0x00); // RESET PORT B
while(TRUE) // always repeat program below
{
if (!input(but1)) // when button 1 pressed
{ while(!input(but1)) //take action after sw1 is released
{}
delay_ms(100);//short delay to debounce the switch
printf("a");
output_high(on);
}
}} |
but there is no signal received at the XCTU coordinator terminal.
I used multimeter to tab the voltage at TX of the PIC18F4620 but there is no any change of voltage level, and i believe thats the problem in initializing or the coding.
Anyone with idea where is the problem?
And i would like to ask, can XBEE [rs232(baud=9600, UART1)] functions in PIC via HS(high speed)?
Thank you guys. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Thu Jun 14, 2012 4:39 am |
|
|
quickly...
1) Divide and conquer. Eliminate the XBEE modules and just use RS232 to debug your programs. Once you've got them running 100% correctly THEN wire in the XBEE modules and retest.
2) There are problems with your code. a) You should add the 'errors' option to the use RS232(....) line.
b) using set_tris..... is not needed as the compiler will automatically set the registers for I/O as required.
c) you never reset ON.
d) naming a pin ON is bad (well poor anyway), call it 'status LED' or something other that 'ON'. Same for BUT1, call it BUTTON1. Easier to read, understand and self describes the use of the variable.
Unlike 40 years ago you're allowed more than 2 characters to name variables.... |
|
|
wongchunyuan
Joined: 14 Jun 2012 Posts: 3
|
|
Posted: Thu Jun 14, 2012 8:54 am |
|
|
Thanks tem, i tried to debug one by one and finally i managed to communicate via xbee! but now i am having another problem in counting, which i am asking in another thread now at http://www.ccsinfo.com/forum/viewtopic.php?p=163615#163615. Would you mind to have a look there? thanks a million! |
|
|
|
|
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
|