View previous topic :: View next topic |
Author |
Message |
haden
Joined: 13 Feb 2012 Posts: 6
|
xbee at commands |
Posted: Mon Feb 13, 2012 2:05 pm |
|
|
Hi
I've searched and read a lot in this nice forum, but I have no clue where to start. I'm totally newbie into PIC, but what a new world that had opened up... I hope some of you can point me in the right direction.
I have a PIC 16F886 connected to a xbee and are able to send data to another xbee connected to my pc and read the values in X-CTU terminal.
So far so good, but how do I make my PIC talk with the local xbee?
I want to execute the following:
+++ to enter command mode
ATSL [enter] to get the low part of the serialnumber
ATCN [enter] to exit command mode
send the result of ATSL to the pc.
Thanks
Kim |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9225 Location: Greensville,Ontario
|
|
Posted: Mon Feb 13, 2012 3:26 pm |
|
|
Your xbee module must have a datasheet with a list of commands/data structure,etc. Surely there's a sample program on the mfr.s website?
Sending '+++' is easy but HOW is the xbee connected? I2C,SPI,SIO ? we don't know as we don't know what module you're using !
The more info you give the faster we can respond.
'+++' is the old Hayes 'escape' command code.... |
|
|
haden
Joined: 13 Feb 2012 Posts: 6
|
|
Posted: Tue Feb 14, 2012 12:23 am |
|
|
Thanks
Sorry for not providing that.
Its a DIGI XBEE series 2 module, in AT mode that is connected using the UART of the PIC(pin 17,18). I'm using the plain old rx/tx.
If other connection methods are prefered, please tell me so and i can look at that.
But to learn something I would like to understand how to use the UART.
kim |
|
|
dezso
Joined: 04 Mar 2010 Posts: 102
|
|
Posted: Tue Feb 14, 2012 1:19 am |
|
|
Code: | #use rs232(baud=9600, xmit=PIN_C2,rcv=PIN_C3)
void SendSerial()
{
printf("+++");
printf("ATSL"\r);
printf("ATCN"\r);
}
|
Not sure what you want to do, hope this helps. _________________ I'm could be wrong many time's, at least I know what I'm doing |
|
|
haden
Joined: 13 Feb 2012 Posts: 6
|
|
Posted: Tue Feb 14, 2012 1:25 am |
|
|
Thanks
I can send using the printf, but how do i receive the result from the ATSL returned from the xbee?
Kim |
|
|
dezso
Joined: 04 Mar 2010 Posts: 102
|
|
Posted: Tue Feb 14, 2012 10:59 pm |
|
|
I don't have your hardware or even a simulator running here.
This is just an IDEA...
Code: | #use rs232(baud=9600, UART1, ERRORS, PARITY=N, BITS=8, STOP=1)
char serialText[];
int8 i = 0;
int8 SerialLenght = 16;
void GetSerial(void)
{
printf("+++");
printf("ATSL\r");
Enable_interrupts(INT_RDA);
}
void CloseGetSerial(void)
{
Disable_interrupts(INT_RDA);
printf("ATCN\r");
sprintf(LCD_PUTC,serialText,n);
}
#INT_RDA
void isr_rda(void)
{
char c;
c = getc();
serialText[i] = c;
if(i==16)
CloseGetSerial();
i++;
}
void main(void)
{
clear_interrupt(INT_RDA);
enable_interrupts(GLOBAL);
GetSerial();
while(true)
{
Blinky();
}
} |
_________________ I'm could be wrong many time's, at least I know what I'm doing |
|
|
haden
Joined: 13 Feb 2012 Posts: 6
|
|
Posted: Wed Feb 15, 2012 1:43 pm |
|
|
I've tried modify one the examplefiles, but no luck.
Code: | #include "16F886.h"
#fuses NOLVP,NOWDT,PUT,BROWNOUT,INTRC_IO
#use delay(clock=2000000)
#use rs232(baud=9600, xmit=pin_C6, rcv=pin_C7, ERRORS, PARITY=N, BITS=8, STOP=1)
#define BUFFER_SIZE 32
BYTE buffer[BUFFER_SIZE];
BYTE next_in = 0;
BYTE next_out = 0;
#int_rda
void serial_isr() {
int t;
buffer[next_in]=getc();
t=next_in;
next_in=(next_in+1) % BUFFER_SIZE;
if(next_in==next_out)
next_in=t;
}
#define bkbhit (next_in!=next_out)
BYTE bgetc() {
BYTE c;
while(!bkbhit) ;
c=buffer[next_out];
next_out=(next_out+1) % BUFFER_SIZE;
return(c);
}
void main() {
enable_interrupts(int_rda);
enable_interrupts(global);
printf("\r\n\PIC Alive\r\n");
do {
delay_ms(10000);
printf("+++");
printf("\r\nData => ");
while(bkbhit)
putc( bgetc() );
} while (TRUE);
} |
Sending the +++ to the xbee should return ok, but it just return +++
Kim |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9225 Location: Greensville,Ontario
|
|
Posted: Wed Feb 15, 2012 5:47 pm |
|
|
I downloaded the manual for your xbee device....
I suggest you reread the ..
Section 2.2.4 Command mode....
You _must_ do exactly as they say...
pause 1 second
send +++
pause 1 second
you do this....
printf("+++");
printf("\r\nData => ");
You're sending \r\nDATA = > " to the xbee which is NOT allowed !
You MUST read the manual and do as they say,sending 'weird' data withing useconds of the +++ isn't correct. |
|
|
gpsmikey
Joined: 16 Nov 2010 Posts: 588 Location: Kirkland, WA
|
|
Posted: Wed Feb 15, 2012 9:21 pm |
|
|
Those 1 second gaps are part of the "Hayes" command set - if you skip them, you are not following the standard and it will simply ignore you. As Temtronic points out, you MUST include them.
mikey _________________ mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3 |
|
|
haden
Joined: 13 Feb 2012 Posts: 6
|
|
Posted: Thu Feb 16, 2012 10:24 am |
|
|
Thank you very much. its awesome
I've change it to:
Code: | void main() {
enable_interrupts(int_rda);
enable_interrupts(global);
delay_ms(2000);
printf("PIC Alive\r");
do {
delay_ms(2000);
printf("+++");
delay_ms(2000);
printf("ATSL\r");
delay_ms(2000);
printf("ATCN\r");
delay_ms(2000);
while(bkbhit)
putc( bgetc() );
} while (TRUE);
} |
And I can now get the result back to my terminal.
Now I just need to make it into some usefull functions.
Kim |
|
|
haden
Joined: 13 Feb 2012 Posts: 6
|
|
Posted: Sun Feb 19, 2012 2:02 pm |
|
|
The above code returns:
OK
4031F854
OK
But how can I verify that the +++ command returns OK before i continue? I've looked at the strcmp method, but can't figure out where to put it.. C is not my best friend
Another question for making me understand my code: Is it possible to debug the code runtime to view what happens? I'm used to C# so I'm just trying to understand whats possible in this world. I have a iCP02 programmer from piccircuit
Kim |
|
|
|