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

'AT' commands used in a C program

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



Joined: 29 Jan 2008
Posts: 3

View user's profile Send private message MSN Messenger

'AT' commands used in a C program
PostPosted: Thu Jan 31, 2008 3:03 pm     Reply with quote

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







PostPosted: Thu Jan 31, 2008 3:47 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Jan 31, 2008 7:39 pm     Reply with quote

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

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

PostPosted: Fri Feb 01, 2008 1:43 am     Reply with quote

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

View user's profile Send private message MSN Messenger

PostPosted: Fri Feb 01, 2008 6:19 am     Reply with quote

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

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

PostPosted: Fri Feb 01, 2008 6:58 am     Reply with quote

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

View user's profile Send private message MSN Messenger

PostPosted: Fri Feb 01, 2008 8:07 am     Reply with quote

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 Smile
Guest








PostPosted: Sun Apr 13, 2008 12:02 am     Reply with quote

is it possible to send strings in hyperterminal to PIC? or its just sending characters to PIC but not strings of characters?
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