We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
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...
Don't you see any responsesn when you use the Hyperterminal?
Where is the code that looks for, and processes, any responses?
http://www.keil.com/forum/docs/thread12899.asp
i m getting ack from hyperterminal aswell as i m able to send msg with hyperterminal..But I did't get ur point in saying looking for ack from modem when sending AT cmds from 8051. ok if i m reading the ack also where will i display it to see and verify..??? pls pls If u know the code for reading ack get me pls....
Here is one more assembly code even for this also same problem:
org 0000h
start: mov TMOD, #20H mov TH1, #-3 mov SCON, #50H setb TR1 mov dptr,#mydata1 Tagaina3: clr a movc a,@a+dptr jz Texita3 clr ti mov sbuf,a inc dptr Therea3:jnb ti,Therea3 sjmp Tagaina3
Texita3:mov a,#0dh clr ti mov sbuf,a There1a3: jnb ti,There1a3 lcall delay2 mov dptr,#mydata2 Tagain1a3: clr a movc a,@a+dptr jz Texit1a3 clr ti mov sbuf,a inc dptr There2a3:jnb ti,There2a3 sjmp Tagain1a3 Texit1a3:mov a,#0dh clr ti mov sbuf,a There3a3:jnb ti, There3a3 lcall delay2
mov dptr,#mydata3 Tag: clr a movc a,@a+dptr jz Tex clr ti mov sbuf,a inc dptr Ther:jnb ti,Ther sjmp Tag Tex: mov a,#1ah clr ti mov sbuf,a There:jnb ti, There CLR TR1 lcall delaya lcall delaya lcall delaya lcall delaya lcall delaya lcall delaya mydata1:db 'at+cmgf=1',0 mydata2:db 'at+cmgs="+919964310430"',0 mydata3:db 'TOWED! TOWED! YOU MSG HAS BEEN RECIEVED ',0
delay2: MOV R5,#20H BHERE3: MOV R6,#0FFH BHERE2: MOV R7,0FFH BHERE1: DJNZ R7,BHERE1 DJNZ R6,BHERE2 DJNZ R5,BHERE3 RET
delaya: mov r0,#0ffh vahere2:mov r1,#0ffh vahere1:djnz r1,vahere1 djnz r0,vahere2 ret
end
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...
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...