This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Pls Help me to send AT cmds to GSM modem frm 8051

I m able to send the msg from hyperterminal with following commands.

AT
AT+CMGF=1
AT+CMGS=+91..MOBILE NO
SMS TEXT
ctrl+z

and when i wrote the following c-code to send the same text msg using 8051 serial port i m not able to send the text. code is as below;

#include <REG52.H>
void Send(unsigned char);
void MSDelay (unsigned int);
unsigned int i;
unsigned char msg1[]="AT";
unsigned char msg2[]="AT+CMGF=1";
unsigned char msg3[]="AT+CMGS=+91..mobile no";
unsigned char msg4[]="TEMPERATURE";

void main()
{

//*************serial communication initialization**********// P1 = 0x00; //Set port 1 as output TMOD = 0x20; //timer 1,mode 2(auto-reload) TH1 = -3; //9600 baud rate SCON = 0x50; //8-bit,1 stop, REN enabled TR1 = 1; //start timer 1

for(i=0;msg1[i]!='\0';i++) Send(msg1[i]); Send(0x0D); Send(0x0A); MSDelay(100);

for(i=0;msg2[i]!='\0';i++) Send(msg2[i]); Send(0x0D); Send(0x0A); MSDelay(100);

for(i=0;msg3[i]!='\0';i++) Send(msg3[i]); Send(0x0D); Send(0x0A); MSDelay(100);

for(i=0;msg4[i]!='\0';i++) Send(msg4[i]); Send(0x1A); while(1);
}

void Send(unsigned char x)
{ SBUF = x; while (TI==0); TI=0;
} void MSDelay (unsigned int value)// Delay routine { unsigned int x,y; for (x=0;x<3500;x++) for (y=0;y<value;y++);

}

------------------------------------------------------
i Have my project submission in 5 days.. pls pls help me out!!!!! Thanks in adwance...

Parents
  • When you type commands manually in Hypoterminal, you wait for the "OK" response from one command before starting to type the next, don't you?

    You need to have your program adopt the same approach - because the modem is not ready to accept the next command until it has given its response to the previous one!

    Similarly, for the SMS, the modem is not ready to accept the text of the message until it has given the '>' prompt

    You also have to account for the possiblity that the modem might say ERROR instead of giving the prompt or OK...

Reply
  • When you type commands manually in Hypoterminal, you wait for the "OK" response from one command before starting to type the next, don't you?

    You need to have your program adopt the same approach - because the modem is not ready to accept the next command until it has given its response to the previous one!

    Similarly, for the SMS, the modem is not ready to accept the text of the message until it has given the '>' prompt

    You also have to account for the possiblity that the modem might say ERROR instead of giving the prompt or OK...

Children
  • Ya i got your point... also i have accounted for responces by providing enough delays. But still its not working out.

    Can i observe the response by any means? and is there any specific time delay to be provided?

    hay i m very happy that u r providing me enough guidence..

  • If the AT standard intended delays to be used, then the documentation for the command would contain information about minimum delays required,

    But no, the command is not designed for use with fixed delays. It is designed for use in two-way mode, where your side catches any output from the modem, and adjusts your actions based on the responses.

    This forum, and the web in general, is peppered with discussions and suggestions and sample code.

  • No, that is not "accounting" for the responses - that is simply ignoring them!

    You need to read the responses, and handle them appropriately.

    "Can i observe the response by any means?"

    It's your program that needs to read & interpret them.

    It is simply a matter of receiving serial data.

    "is there any specific time delay to be provided?"

    No, but it is wise to have a timeout so that your program doesn't get stuck indefinitely if the response is missed or corrupted, etc...