View previous topic :: View next topic |
Author |
Message |
aesli
Joined: 29 Jan 2008 Posts: 3
|
'AT' commands used in a C program |
Posted: Thu Jan 31, 2008 3:03 pm |
|
|
Hi guys
does anybody have any idea how I have to implement my AT commands in the C program that it is possible to communicate with a Zigbee node?
I use a PIC to send AT commands to a Zigbee node but there are some problems with the C program.
this program just should send a AT command to the node which so turns on the LED on the node
Code: | #include "test.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char at_openPort4[]={"ats0d4=1\r"};
char at_flashLedOn[]={"ats0f4=0\r"};
char at_flashLedOff[]={"ats0f4=1\r"};
void main()
{
delay_ms(2000);
puts(at_openPort4); //set I/O4 as an output
delay_ms(5000);
puts(at_flashLedOn); //turn on the LED
} |
cheers for any help
N.D. |
|
|
KamPutty Guest
|
|
Posted: Thu Jan 31, 2008 3:47 pm |
|
|
Hey ND,
Do you need to send a <CR> also with the <LineFeed>
char at_openPort4[]={"ats0d4=1\r\n"};
~Kam (^8* |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Thu Jan 31, 2008 7:39 pm |
|
|
I'm also missing the definition of the RS232 parameters. Most likely you are now sending at the wrong baudrate.
Code: | #use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS) | Change the baudrate and pin numbers according to your hardware.
At the end of your program add an infinite loop. Now when your program reaches the end it executes a sleep instruction by which the last character in the UART is never transmitted. Code: | void main()
{
...
while (TRUE)
{
// Loop forever
}
} |
|
|
|
Foppie
Joined: 16 Sep 2005 Posts: 138 Location: The Netherlands
|
|
Posted: Fri Feb 01, 2008 1:43 am |
|
|
In addition of the above replies. You might have to send a string to put the zigbee module in at mode. The zigbee modules I use require "+++" before it enters AT mode. |
|
|
aesli
Joined: 29 Jan 2008 Posts: 3
|
|
Posted: Fri Feb 01, 2008 6:19 am |
|
|
thanks for the answers
the thing is if I am using hyper terminal every thing is working fine.
But looks like I don't get the commands through the C program
thats the fuses and rs 232 configuration I'm using for the program above
Code: |
#include <18F4520.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES HS //High speed Osc (> 4mhz)
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOBROWNOUT //No brownout reset
#FUSES BORV25 //Brownout reset at 2.5V
#FUSES NOPUT //No Power Up Timer
#FUSES NOCPD //No EE protection
#FUSES NOSTVREN //Stack full/underflow will not cause reset
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT //Program memory not write protected
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES NOIESO //Internal External Switch Over mode disabled
#FUSES NOFCMEN //Fail-safe clock monitor disabled
#FUSES PBADEN //PORTB pins are configured as analog input channels on RESET
#FUSES NOWRTC //configuration not registers write protected
#FUSES NOWRTB //Boot block not write protected
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOEBTRB //Boot block not protected from table reads
#FUSES NOCPB //No Boot Block code protection
#FUSES LPT1OSC //Timer1 configured for low-power operation
#FUSES MCLR //Master Clear pin enabled
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#use delay(clock=20000000)
#use rs232(baud=19200,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
|
if it work with hyper terminal do I have to use the string "+++" like foppie says, and how do you implement it in your C code?
cheers for help
N.D. |
|
|
Foppie
Joined: 16 Sep 2005 Posts: 138 Location: The Netherlands
|
|
Posted: Fri Feb 01, 2008 6:58 am |
|
|
If you don't need to send the "+++" in hyperterminal then you don't need it in your PIC as well.
Have you tried to connect your PIC to a PC and look if the strings are transmitted by the PIC? |
|
|
aesli
Joined: 29 Jan 2008 Posts: 3
|
|
Posted: Fri Feb 01, 2008 8:07 am |
|
|
if I connect the rs232 to pc it sends the AT command while I'm using hyper terminal. But it doesn't work with the zigbee node.
May be I start to build up every thing on a bread board. I'm using at the moment the CCS development board.
Thanks for the help though.
I'll keep trying |
|
|
Guest
|
|
Posted: Sun Apr 13, 2008 12:02 am |
|
|
is it possible to send strings in hyperterminal to PIC? or its just sending characters to PIC but not strings of characters? |
|
|
|