Is this gsm interfacing program correct

Status
Not open for further replies.

uday mehta

Advanced Member level 4
Joined
Dec 30, 2011
Messages
104
Helped
6
Reputation
12
Reaction score
6
Trophy points
1,298
Visit site
Activity points
1,979
I have write a code for sending message form gsm300 using 8051.
but it is not working.
plz tell me where is the problem?
in the program or in ckt?

Code:
#include<reg51.h>
#include<string.h>
#include<absacc.h>
#include<stdlib.h>
#include<ctype.h>

void delay(unsigned int i);
void tx0(unsigned char);
void SMSString(unsigned char*text) ;
void init();
void send_a_message();
//void call();


// Moblie no.of Owner
unsigned char code Mob_no[]= "+917792849639"; 




void delay(unsigned int i)
{
        unsigned int k, l;
        for(k=0;k<i;k++)
        for(l=0;l<1000;l++);
}

void init()
{
	P0=0x00;
	TL1=0XFD; //9600 @ 11.0592
	TH1=0xFD;
	TMOD=0x20;
	SCON=0x50;
	TR1=1;
}


void SMSString(unsigned char* text) //function to send SMS using GSM modem
{
	while (*text)
	{
		tx0(*text++);
	}
} 
       
void tx0(unsigned char x) //send data to serial port 0
{
	EA=0;
	SBUF=x;
	while(TI==0);
	TI=0;
	EA=1;
}

void send_a_message()
{
 SMSString( "AT+CMGF=1\r"); // select text mode for sms
 delay(50);

 SMSString("AT+CMGS=\"");
 SMSString(Mob_no);
 SMSString("\"\r");
 delay(1);
 SMSString("somebody entered incorrect password");
 delay(100);
 tx0(0x1A); // Ctrl+z
 delay(10);
}

/*void call()
{
 SMSString("ATD+917792849639;\r");
 
 delay(1);
 delay(10);
}
*/

void main ()
{

init();

SMSString("AT\r"); // AT commands to initialize gsm modem
delay(50);

SMSString( "ATe0\r"); // turn off echo
delay(50);

SMSString( "AT&W\r"); // save settings
delay(50);

send_a_message();
delay(200);

//call();
while(1);

}


 

uday increase the delay here and check
Code:
void send_a_message()
{
 SMSString( "AT+CMGF=1\r"); // select text mode for sms
 [COLOR="#FF0000"]delay(200);[/COLOR]

 SMSString("AT+CMGS=\"");
 SMSString(Mob_no);
 SMSString("\"\r");
 [COLOR="#FF0000"]delay(200);[/COLOR]
 SMSString("somebody entered incorrect password");
 [COLOR="#FF0000"]delay(200);[/COLOR]
 tx0(0x1A); // Ctrl+z
 [COLOR="#FF0000"]delay(200);[/COLOR]
}
 
Are you simulating in Proteus or testing in hardware ? If simulating in Proteus then connect SIM300 to PC, remove MAX232 from Proteus file and add COMPIM. Connect COMPIM directly to 8051 UART pins. Set baudrate for COMPIM. Set COM port for COMPIM. Additionally you can use eterlogic Virtual Serial Port Emulator (VSPE) and create a mapper type device and map PC hardware COM port to USB Virtual COM port used by SIM300. Then set COM port in COMPIM to hardware COM port.
 
The circuit assumes that you have a SIM300 terminal with built-in MAX232 and DB9 connector to be connected to a PC. Is it so? The modem usually expects handshake signals set to an active level, DTR(pin 4) and RTS (pin7) set to high level.

Secondly the code expects SIM PIN entry to be disabled or the modem already registered to the network. Did you?

Finally it's problematic to operate a modem write-only without waiting on command responses. The delay between sending the CMGS command and the ">" request for entering the message can e.g.vary.

It should be also noted that your code doesn't perform autobaud detection, you need to send isolated "A" and "T" characters with delay between to do it.
 
yes I have SIM300 terminal with built-in MAX232 and DB9 connector to be connected to a PC.
second when I make a call to the number which I inserted in the modem it's call indication LED blinks. means when it can receive a call then it can also make a call or send a sms. so is it necessary to register to the network?

for isolated "A" and "T". I will modify the function "SMSString" as
void SMSString(unsigned char* text) //function to send SMS using GSM modem
{
while (*text)
{
tx0(*text++);
delay(100);
}
}

and for checking the response what should I do. actually this is my first program so I don't know how to check command response.
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…