Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

C program to send AT Commands..is it correct???

Status
Not open for further replies.

truth_seeker

Member level 1
Joined
Dec 7, 2005
Messages
37
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,620
at commands in c

Hello all ,

my graduation project has a part where PIC microcontroller should be connected to a mobile phone , which will use the GPRS service to send the received data from the microcontroller

here is a code to send the needed AT Commands to the mobile phone to open the GPRS connection..it has no errors ..but still no response from the mobile , and the G sign which indicates that GPRS is activated doesn't appear on the mobile screen.

I use PIC 18F4550 , nokia 6610i mobile phone , and I used a zener diode instead of max232 between the microcontroller and the mobile phone.



Code:
#include <string.h>  
#include <p18f4550.h>
#include<portb.h>
#include<usart.h>	
#include<delays.h>
#define	false	0
#define true	1
#define maxsize 10

	


int i; 
char COMMAND[5] = {"AT","AT+CGATT=1","AT+CGDCONT=1,IP,INTERNET", "AT+CGACT=1,1","ATD*99#"};

char RESPONSES[5] = {"OK","OK","OK","OK","CONNECT"};

char tmpdata; // Used in receive function


int READY = false ;
int FLAG = true ;

  
void receive(int j);
void send(int k);
void initialize (void) ;



void main(void) 


    {
TRISD=0;
TRISCbits.TRISC6 =0;     
TRISCbits.TRISC7 =1; 
TRISAbits.TRISA4 =0; 
		
//configures Usart with boud rate 9600  ? (4*9600)/ 2400000 -1=624 
	
OpenUSART(USART_TX_INT_OFF & USART_RX_INT_OFF & USART_SYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_LOW,624);
PORTAbits.RA4= 1;

for (i=0;i<=4;++i)
{
send (i);
if(i==4) receive(7);
else   receive(2);
 while(FLAG)


        {
        if (strcmp(tmpdata,RESPONSES[i]))
   {
if (i==0)PORTDbits.RD0= 1;  // ok 
if (i==1)PORTDbits.RD1= 1;
if (i==2)PORTDbits.RD2= 1;
if (i==3)PORTDbits.RD3= 1;
if (i==4)PORTDbits.RD4= 1;
 Delay10TCYx( 5 );         
  READY = 1;
            FLAG = false;
        }

        else 


            {
if (i==0)PORTDbits.RD0= 0;  //error
if (i==1)PORTDbits.RD1= 0;
if (i==2)PORTDbits.RD2= 0;
if (i==3)PORTDbits.RD3= 0;
if (i==4)PORTDbits.RD4= 0;

Delay10TCYx( 5 );
            send(i);
            if(i==4) receive(7);
            else   receive(2);
        }

    }

    if (READY == 1)


        {
        FLAG = true;
    }

  }
  
}

void receive( int j)


    {
  
 if( DataRdyUSART( ))
     getsUSART(tmpdata,j); //read data ;
           

    }  





void send ( int k)

{
putsUSART(COMMAND[i]);
while(BusyUSART());
}



Please tell me if there is anything wrong with this code...

is this the right way to send the AT Commands using C language , or there is another way???

note: on hyper terminal ..the command ..AT+CGDCONT=1,IP,INTERNET ..is written ..AT+CGDCONT=1,"IP","INTERNET"..but the compiler gives an error when I write it this way using C language..why?? is it maybe the problem??

Thanks a lot :|
[/code]
 

how to send a at command through c programming

Hi,

try using this:

char COMMAND[5] = {"AT","AT+CGATT=1","AT+CGDCONT=1,\"IP\",\"INTERNET\"", "AT+CGACT=1,1","ATD*99#"};
 
sending at commands using a c program

Hello ,

thank you guys for replying

as I said..the code doesn't generate any errors....but still no response ..and i don't know what the problem is!!!!!!

snilson...Thanks for your suggestion , I tried it , and you are right..this is how it should be written!!

Can anyone tell me what to do to get a response..or at least to know where the problem is??!!!

Thanks a lot
 

program to send at commands

This was my GSM project which worked perfectly. Extract only the GSM part

Good luck
 
pic send at commands c

the codes seems ok! but what would be the response of the PIC to the hyperterminal? i cannot test it here becoz i'm to busy in designing some projects.

regards,
randell_xtian
:D:D:D:D
 

at command + c program

That was a code written for GSM modem using a 8 bit controller. You can add you AT commands to that or test the modem using only hyperterminal to confirm if the modem responds properly, In which case you can suspect the code or else you cannot debug the modem.
 

send at commands by c

Hello ,

ckshivaram ..thank you very much for the attachment ..the code is very good..but I haven't tried it on my microcontroller yet..hope it works on it , but I still need to understand why my code doesn't work!!!

randell_xtian , when I connected the PIC to the hypertermianl..it gave me meaningless characters and symbols on the hyperterminal..what does that mean??

thank you guys
 

at+cgdcont .c

May be there is some mismatch on the serial communication baudrate? Most of time this is the mainly reason for communication trouble between micro and modem or phone.

Cheers
F.F. a.k.a. Powermos
 

send at command c

Hello i want to know what will happen if the GPRS connection suddenly fail(i mean if something happens with the GSM Cell)? Will i gonna loose data and is there any AT command to prevent this?
Thanks for the response in advance!!
 

how to send at command c

the device is communicating.
see the PIC micro respond to the signal give by the Hyperterminal. the only one that i can see possible error is the message transmitted by the device. for example when i press any key in my keyboard(computer), what would be the value of the hyperterminal(message?). (connect the device to hyperterminal and press any key. see the respond of the hyperterminal).

to rus40
when their is no available signal coming from a cell site. the device should be automatically save its previous data.
yes there is a command respond on this situation.
 

at commands microcontroller c programming

can you upload the schematic you are using i suspect something is wring there
 

at commands in c

Hi every1,
I don't know which compiler will let you get away with writing
Code:
char COMMAND[5] = {"AT","AT+CGATT=1","AT+CGDCONT=1,\"IP\",\"INTERNET\"", "AT+CGACT=1,1","ATD*99#"};
but if there is one, change it because it’s no good…
Where I learnt C, they taught me to write
Code:
char *COMMAND[] = {"AT","AT+CGATT=1","AT+CGDCONT=1,\"IP\",\"INTERNET\"", "AT+CGACT=1,1","ATD*99#"};
char *RESPONSES[] = {"OK","OK","OK","OK","CONNECT"}; 
char *tmpdata; // Used in receive function
instead.
You would then access the commands like COMMAND[0] for "AT", COMMAND[1] for "AT+CGATT=1" and so on. The same goes for RESPONSES.
How could you guys miss that? …or did I totally miss something?!

Arthur
 

at-commands 18f4550

truth_seeker,
Check this topic, I think you will find it useful.


Please note, the HyperTerminal sends the AT-Command as a string. In C, you will need to send the Double-Quote as well so, send the ASCII of the Double-Quote before and after the command. The ASCII of the " is 34 in decimal.

I hope this helps.
 

programs in c to send at command

No seadolphine2000, it doesn't help.
The post you indicate is yet just another proof of cowboy programming.
You don’t need to send the quotation marks! It’s not the quotation marks that make the string a “string”! Quotation marks are just a way of making the compiler understand what we want from it, nothing else.
Someone in there even said
DONT send char by char
instead dump the whole string
which is complete bullsh*t! The only way to do it is to send one char at the time (whether you do it or the library does it for you).
I think you would be better off by starting with a basic course in C programming first…

The only truth that post reveals is that, depending on the device you’re talking to, you might need to send carriage return (CR = 0x0d) and/or line feed (LF = 0x0a). Refer to the device’s manual and do as indicated there.

Arthur
 

gsm at commands *99# login

Thanks for the answer randell_xtian ! :)
Can you tell me the AT command which response to that situation?
 

at+command+c+program

You don’t need to send the quotation marks! It’s not the quotation marks that make the string a “string”! Quotation marks are just a way of making the compiler understand what we want from it, nothing else.

Thanks Arthur0 for the correction, I'm sure that you are right regarding the C-Language. However, I'm talking about something I tested it myself and it works this way, at least in both "MikroBasic" and "Visual Basic".

Thanks again.
 

Hi all.

I'm trying to interface the hex keypad with my GSM project.display the out put oc the LCD.the issue I'm having is that I cant see what I'm typing on the one LCD.

Please advise .I'm using the 8051 for this project.
 

Re: at commands in c

hello all,
i want to interface gsm cell phone(nokia c5) to avr micrcontroller using usb cable is i require any level converter to send & receive text message for home automation.
my connectinon is as follows
microcontroller TTL TX ----> cell phone RX(through USB cabel)
microcontroller TTL RX ----> cell phone TX(through USB cabel)
microcontroller VCC ----> cell phone VCC(through USB cabel)
microcontroller GND ----> cell phone GND(through USB cabel)

is my connection right?
if yes, when i coneect cell phone to controller(using above connection) & transmit at command, but no responce from cell phone.

can anyone post a schematic.

thanks

Hello all ,

my graduation project has a part where PIC microcontroller should be connected to a mobile phone , which will use the GPRS service to send the received data from the microcontroller

here is a code to send the needed AT Commands to the mobile phone to open the GPRS connection..it has no errors ..but still no response from the mobile , and the G sign which indicates that GPRS is activated doesn't appear on the mobile screen.

I use PIC 18F4550 , nokia 6610i mobile phone , and I used a zener diode instead of max232 between the microcontroller and the mobile phone.



Code:
#include <string.h>  
#include <p18f4550.h>
#include<portb.h>
#include<usart.h>	
#include<delays.h>
#define	false	0
#define true	1
#define maxsize 10

	


int i; 
char COMMAND[5] = {"AT","AT+CGATT=1","AT+CGDCONT=1,IP,INTERNET", "AT+CGACT=1,1","ATD*99#"};

char RESPONSES[5] = {"OK","OK","OK","OK","CONNECT"};

char tmpdata; // Used in receive function


int READY = false ;
int FLAG = true ;

  
void receive(int j);
void send(int k);
void initialize (void) ;



void main(void) 


    {
TRISD=0;
TRISCbits.TRISC6 =0;     
TRISCbits.TRISC7 =1; 
TRISAbits.TRISA4 =0; 
		
//configures Usart with boud rate 9600  ? (4*9600)/ 2400000 -1=624 
	
OpenUSART(USART_TX_INT_OFF & USART_RX_INT_OFF & USART_SYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_LOW,624);
PORTAbits.RA4= 1;

for (i=0;i<=4;++i)
{
send (i);
if(i==4) receive(7);
else   receive(2);
 while(FLAG)


        {
        if (strcmp(tmpdata,RESPONSES[i]))
   {
if (i==0)PORTDbits.RD0= 1;  // ok 
if (i==1)PORTDbits.RD1= 1;
if (i==2)PORTDbits.RD2= 1;
if (i==3)PORTDbits.RD3= 1;
if (i==4)PORTDbits.RD4= 1;
 Delay10TCYx( 5 );         
  READY = 1;
            FLAG = false;
        }

        else 


            {
if (i==0)PORTDbits.RD0= 0;  //error
if (i==1)PORTDbits.RD1= 0;
if (i==2)PORTDbits.RD2= 0;
if (i==3)PORTDbits.RD3= 0;
if (i==4)PORTDbits.RD4= 0;

Delay10TCYx( 5 );
            send(i);
            if(i==4) receive(7);
            else   receive(2);
        }

    }

    if (READY == 1)


        {
        FLAG = true;
    }

  }
  
}

void receive( int j)


    {
  
 if( DataRdyUSART( ))
     getsUSART(tmpdata,j); //read data ;
           

    }  





void send ( int k)

{
putsUSART(COMMAND[i]);
while(BusyUSART());
}



Please tell me if there is anything wrong with this code...

is this the right way to send the AT Commands using C language , or there is another way???

note: on hyper terminal ..the command ..AT+CGDCONT=1,IP,INTERNET ..is written ..AT+CGDCONT=1,"IP","INTERNET"..but the compiler gives an error when I write it this way using C language..why?? is it maybe the problem??

Thanks a lot :|
[/code][/QUOTE]
 
Last edited:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top