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.

Interfacing SIM900A with 89S52

Status
Not open for further replies.

gauravkothari23

Advanced Member level 2
Joined
Mar 21, 2015
Messages
640
Helped
5
Reputation
10
Reaction score
4
Trophy points
1,298
Activity points
6,922
Hi all...
I am trying to interface SIM900A with 89S52 to send messages to the mobile phone.
Code:
Code:
#include<reg51.h>
unsigned char *command_ATE0 = "ATE0\r";
unsigned char *command_AT = "AT\r";
unsigned char *command_CMGF = "AT+CMGF=1\r";
unsigned char *command_CMGS = "AT+CMGS=\"+9199********\"\r";
unsigned char *message = "Welcome to the world of Robotics..!";       // Msg 2 be send
unsigned char CTRLZ = 0x1A;  
void gsm();
void puts(unsigned char* ptr);
void putc(unsigned char chr);
void sendsms(void);
void initialize();
void delay(unsigned int time);


void main()
{                                            
 gsm();
 while(1);
}


void gsm()
{
 initialize();
 sendsms();
}

void initialize()
{
 SCON  = 0x50;   /*SCON: mode 1, 8-bit UART, enable receive      */
 TMOD |= 0x20;   /*TMOD: timer 1, mode 2, 8-bit                  */
 TH1   = 0xFD;   /*TH1:  for 9600 baud                           */
 TR1   = 1;      /*TR1:  timer 1 run                             */ 
}

void sendsms()
{
 puts(command_ATE0); 
 delay(50);
 puts(command_AT);
 delay(50); 
 puts(command_CMGF); 
 delay(50);
 puts(command_CMGS);
 delay(50);
 puts(message);
 delay(50);
 putc(CTRLZ);
 
}

void puts(char* p)
{
 char *temp = p;          /*temp pointer so that the actual pointer is not displaced */
 while(*temp != 0x00)
 {
  putc(*temp);  
  temp++;
 } 
}

void putc(unsigned char chr)
{
 SBUF = chr;
 while(TI==0);            /*Wait until the character is completely sent */
 TI=0;                    /*Reset the flag */
}


void delay(unsigned int time)
{
unsigned int y,z;
for(y=0;y<=time;y++)
for(z=0;z<2400;z++)
{
;
}
}
but while stimulating the same in proteus, i am getting an error...
the virtual terminal window display something ugly which i cannot understand.
image of virtual terminal window attached...
can anybody please help me....
 

Attachments

  • untitled.GIF
    untitled.GIF
    91.5 KB · Views: 51

Terminal looks like there were different RS speed. First of all check times with probe.
If in simulation terminal there is autobaud implemented try to several times send "AT\r", or someone tip to use "AAAAAAT\r" on the beginning of communications
 

Terminal looks like there were different RS speed. First of all check times with probe.
If in simulation terminal there is autobaud implemented try to several times send "AT\r", or someone tip to use "AAAAAAT\r" on the beginning of communications

Thanks a lot....
but while testing in circuit it works perfectly...
it sends messages to registered no without any issues....

- - - Updated - - -

and also... if possible than can you please let me know how to send messages to phone numbers stored in string...
like....
unsigned char phone[11]= {"+910000000000"};
so now i would like to send messages to phone number stores in string phone....
what changes should i do....
 

In my opinion in real circuit you have autobaud enabled or baud set to 9600, in proteus there is another baudrate set.
btw. you should first send "AT\r" and then "ATE\r" and the rest of commands.

I don't understand your next question, but I think it could explain. Imagine module as notepad. You can write string, or you can write char by char.
Command is executed when it get "\r" or Ctrl+Z in some case
So you can
puts( "AT+CMGS="+9199********"\r");
or
puts( "AT+CMGS="");
puts("+9199********");
puts(""\r");

or even
putch('A');
putch('T');
putch('+');
.....
.....
putch('\r');

or any combination.

Finally to be sure that everything is ok you should receive module response - especially search for "OK" or "ERROR" string
 

In my opinion in real circuit you have autobaud enabled or baud set to 9600, in proteus there is another baudrate set.
btw. you should first send "AT\r" and then "ATE\r" and the rest of commands.

I don't understand your next question, but I think it could explain. Imagine module as notepad. You can write string, or you can write char by char.
Command is executed when it get "\r" or Ctrl+Z in some case
So you can
puts( "AT+CMGS="+9199********"\r");
or
puts( "AT+CMGS="");
puts("+9199********");
puts(""\r");

or even
putch('A');
putch('T');
putch('+');
.....
.....
putch('\r');

or any combination.

Finally to be sure that everything is ok you should receive module response - especially search for "OK" or "ERROR" string

i have checked and also changed the proteus baudrate to 9600.... but still the same problem continues.....
what can i do now...
are there any other setting which i need to edit it...??

- - - Updated - - -

In my opinion in real circuit you have autobaud enabled or baud set to 9600, in proteus there is another baudrate set.
btw. you should first send "AT\r" and then "ATE\r" and the rest of commands.

I don't understand your next question, but I think it could explain. Imagine module as notepad. You can write string, or you can write char by char.
Command is executed when it get "\r" or Ctrl+Z in some case
So you can
puts( "AT+CMGS="+9199********"\r");
or
puts( "AT+CMGS="");
puts("+9199********");
puts(""\r");

or even
putch('A');
putch('T');
putch('+');
.....
.....
putch('\r');

or any combination.

Finally to be sure that everything is ok you should receive module response - especially search for "OK" or "ERROR" string


as you suggested.... i have tried using
puts( "AT+CMGS="");
puts("+9199********");
puts(""\r");
but it gives me error....
GSM MODEM.C(45): error C103: '<string>': unclosed string
GSM MODEM.c(45): error C305: unterminated string/char const
GSM MODEM.C(46): error C141: syntax error near 'puts'
 

Of course it won't work. check number of parenthesis. I didn't pay attention that editor changed my
Code:
\""
into
Code:
""
so code become unreadable

so in fact it should be

Code:
puts("\"AT+CMGS=");
puts("+9199********");
puts("\"\r");

For proteus problem connect osciloscope and place image - there could be a lot of possible reasons
 
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top