Discussion in "Embedded GSM Development" started by    hiabcwelcome    Mar 5, 2013.
Tue Mar 05 2013, 06:27 am
#1
I have seen thread on http://www.8051projects.net/t41321/embedded-gsm-development/gsm-modem-8051.htm
But i cant get why to check for carriage return(0x0D)?
Also what are the responses from SIM300 for following commands:
AT
ATe0
AT&W
AT+CMGF=1
AT+CNMI=1,2,0,0,0
Anyone can explain me all above commands in details?
Please help urgent
Thank You.
Tue Mar 05 2013, 10:28 am
#2

But i cant get why to check for carriage return(0x0D)?

hiabcwelcome


there are so many messages in that topic, which post are you referring to?

Also what are the responses from SIM300 for following commands:

hiabcwelcome


If I was you i would have tried it myself on modem and see the response. anyways, all commands reply with "\r\nOK\r\n"

Anyone can explain me all above commands in details?

hiabcwelcome


Something new to learn today? I think you should read AT command manual by yourself and see what these commands do. If you find any problem do post again. We will answer you for sure.

Tue Mar 05 2013, 09:01 pm
#3
@Ajay Thanks
I want to read SMS from SIM300 GSM. I am using AT89C51 with RS232 communication.
I have tried following code I want suggestions for reading SMS.

#include<reg52.h>

#include<string.h>


//DEFINE CONSTANT
#define Baud_rate 0xFA  // BAUD RATE 4800                     

/********************************************* LCD control signals declaration ***************************************************/
sbit RS = P1^0;     	// Register Select line
sbit RW = P1^2;  		// Read/write line
sbit Enable = P1^1; 	// Enable line

#define LCD_PORT P2

//DEFINE PROTOTYPES
void serialinitialize(void);
void sendbyteserially(unsigned char* text);
void tx(unsigned char x);
void delayms(unsigned int val);
void recbyteserially();
void check();

unsigned char cmd1[]={"AT\r"},i,msg1[50],k,n,rcv1[2],rcv2[10];
unsigned char cmd2[]={"ATe0\r"};
unsigned char cmd3[]={"AT&W\r"};
unsigned char cmd4[]={"AT+CMGF=1\r"};
unsigned char cmd5[]={"AT+CNMI=1,2,0,0,0\r"};

void send_cmd(unsigned char);
void send_data(unsigned char*);
void send_char(unsigned char);
void LCD_init(void);
void send_cmd(unsigned char Command);
void send_data(unsigned char *String);


void main()
{
	LCD_init();
	LCD_PORT = 0x00; 
	send_cmd(0x80);   	  			 // Force cursor to beginning of 1st line
 	delayms(100);   			
  	send_data("Hello "); 		 	 // Send data string
	delayms(50);    			
  	send_data("For Ads");
  	delayms(10);
  	send_cmd(0xC0);    				 // Force cursor to beginning of 2nd line
  	delayms(10);    				
  	send_data("Contact Number"); // send data string
  	delayms(50);    				 
  	send_cmd(0x01);    				 // Clear display
  	delayms(10);    			
  	send_cmd(0x80);    				 // Force cursor to beginning of 1st line
  	delayms(50);   					 
  	send_cmd(0x01);    				 // Clear display
  	delayms(10);   				

	serialinitialize();
	send_data("Checking GSM");
	delayms(50);   			
	 
	sendbyteserially(cmd1);
	recbyteserially();
	check();
	
	sendbyteserially(cmd2);
	recbyteserially();
	check();

	sendbyteserially(cmd3);
	recbyteserially();
	check();

	sendbyteserially(cmd4);
	recbyteserially();
	check();
		
	sendbyteserially(cmd5);
	recbyteserially();
	check();

	while(1) 
	{
//		recbyteserially1();		
	}
}

void serialinitialize(void)		           // INITIALIZE SERIAL PORT
{
	TMOD = 0x20;	                       // Timer 1 IN MODE 2 -AUTO RELOAD TO GENERATE BAUD RATE
	IE=0X90;   							   // Enable serial interrupt
	SCON = 0x50;			               // SERIAL MODE 1, 8-DATA BIT 1-START BIT, 1-STOP BIT, REN ENABLED
	TH1 = Baud_rate;		               // LOAD BAUDRATE TO TIMER REGISTER
	TR1 = 1;			                   // START TIMER
}

void sendbyteserially(unsigned char* text) //function to send SMS using GSM modem
{
    unsigned char count = 0;
	while (text[count])
	{
		tx(text[count++]);
	}
}

void tx(unsigned char x)				   //send data to serial port
{
	EA=0;
	SBUF=x;
	while(TI==0);
	TI=0;
	EA=1;
}

void delayms(unsigned int val)
{
	unsigned int i,j;
 	for(i=0;i<=val;i++)
 	{
  		for(j=0;j<=1275;j++)
    	;// no operation produce 1us time delay
 	}
}

void recbyteserially()
{
	for(i=0;i<2;i++)
	{
		while(RI == 0);
	  	rcv1[i] = SBUF;			            // LOAD DATA TO SERIAL BUFFER REGISTER			            	// WAIT UNTIL TRANSMISSION TO COMPLETE
	  	RI = 0;				                	// CLEAR TRANSMISSION INTERRUPT FLAG
	}

}

void recbyteserially1()
{
 	for(i=0;i<50;i++)
 	{
 		while(RI == 0);
	  	rcv2[i] = SBUF;			            // LOAD DATA TO SERIAL BUFFER REGISTER			            	// WAIT UNTIL TRANSMISSION TO COMPLETE
	  	RI = 0;				                	// CLEAR TRANSMISSION INTERRUPT FLAG
 	}
}

void send_data(unsigned char *String)
{
	unsigned char i=0;
	while(String[i]!='\0')
	{    
  		LCD_PORT = String[i++];
  		RS = 1;    // Select Data Register
  		RW = 0;    // write operation
  		Enable = 1;   // High to Low pulse provided on the enable pin with nearly 1ms(>
450ns)
  		delayms(1);   // 1 millisec delay
  		Enable = 0;
  		if(i>
=16)   // If the number of characters in the string >
 16, then the below command automatically 
  		send_cmd(0x1C);  // Shift the display right side 
  		delayms(10);   // 100 millisec delay
 	}
}
void LCD_init()
 {
 	send_cmd(0x38);      // configuring LCD as 2 line 5x7 matrix
 	send_cmd(0x0E);      // Display on, Cursor blinking
 	send_cmd(0x01);      // Clear Display Screen
 	send_cmd(0x06);      // Increment Cursor (Right side)
}


void send_cmd(unsigned char Command)
{
 	LCD_PORT = Command;
 	RS = 0;      // Select Command Register
 	RW = 0;    // write operation
	Enable = 1;      // High to Low pulse provided on the enable pin with nearly 1ms(>
450ns)
	delayms(1);   // 1 millisec delay
 	Enable = 0;
}

void check()
{
 	if(strcmp(rcv1,"ok")==0||strcmp(rcv1,"OK")==0)
	send_data("OK");
	else
	send_data("Error");
}


[ Edited Wed Mar 06 2013, 06:06 am ]
Wed Mar 06 2013, 10:31 am
#4
your check function will always fail as modem sends response as "\r\nOK\r\n" which means total 6 bytes and you are reading only two and then comparing it. so you need to change your code accordingly.
Wed Mar 06 2013, 08:42 pm
#5
Thanks Ajay for correction.
1. I am using command sequence as follows:
AT
ATe0
AT&W
AT+CMGF=1
AT+CNMI=1,2,0,0,0
After this which commands should i use to read SMS?
2. Also I want to know more about ATe0 i.e. what do u mean by turning echo off?Is that necessary to use this command?
Thu Mar 07 2013, 12:56 pm
#6
echo means whatever you send to modem, modem sends it back. if you do not turn off echo you get response data mixed with command. so becomes difficult to process it. turning off echo only gives you responses.
Thu Mar 07 2013, 10:25 pm
#7
What about

1. I am using command sequence as follows:
AT
ATe0
AT&W
AT+CMGF=1
AT+CNMI=1,2,0,0,0
After this which commands should i use to read SMS?

Fri Mar 08 2013, 05:40 pm
#8
AT+CMGR=[sms location]

where sms location on simcard, can be any number between 1 to 30 (I think).


[ Edited Fri Mar 08 2013, 05:41 pm ]
Thu Mar 14 2013, 06:27 am
#9
According to you i have changed code and added rcemsg function to read message
But its not working again. It is not printing New message on LCD
Please help


void rcemsg()
{
	while(RI!=1);
	ch=SBUF;
	LCD_send(ch);
	while(ch!="9")
	{
		RI=0;
		while(RI!=1);
		ch=SBUF;
		LCD_send(ch);
	}
	LCD_send(ch);
	while(ch!="1")
	{
		RI=0;
		while(RI!=1);
		ch=SBUF;
	}
	LCD_init(); 
	if(count!=10)
	{
		num[i]=ch;
		RI=0;
		while(RI!=1);
		{
		ch=SBUF;
		count++;
		}
	}
	num[i]='\0';
	LCD_init();
	send_data("New Message");
	while(ch!="$")
	{
		RI=0;
		while(RI!=1);
		ch=SBUF;
	}
	i=0;
	while(ch!="$")
	{
		RI=0;
		msg[i]=ch;
		i++;
		while(RI!=1);
		ch=SBUF;
	}
	msg[i]='\0';
	send_data(msg);
	return;
}
Sat Mar 16 2013, 05:16 pm
#10
I think you need to work on your C skills a bit. this way you will find it difficult to write code.

// is this how you compare character?
while(ch!="9")

// It should be like this
while(ch!='9')

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

ArktiTic
Sun May 05 2024, 07:06 pm
CesslasyNear
Sun May 05 2024, 02:58 pm
chimichmedic1204
Sun May 05 2024, 11:06 am
Jamiegob
Sun May 05 2024, 10:11 am
Gregoryjed
Sun May 05 2024, 10:02 am
Mariocax
Sun May 05 2024, 08:51 am
WilliamErync
Sun May 05 2024, 02:35 am
Danielnof
Sat May 04 2024, 11:12 pm