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.

Unable to read sms from GSM which is interfaced to 8051

Status
Not open for further replies.

deep0177

Newbie level 6
Newbie level 6
Joined
May 31, 2013
Messages
11
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,354
Hi want to read sms from GSM which is interfaced to 8051 micro controller , i am using Sim 900 A Gsm module whenever i tried to read the sms i am getting some garbage value as a response, both GSM and serial comm. baud rate are set at 9600 .


Any suggestions regarding this please.


Regards
Deepak
 

Hi Deep0177

First did you checked the AT command for reading sms from the terminal which is you are using in your system.

Try these following commands
AT+CSQ
AT+CREG?
AT+CPMS="SM"
> It will show the Sim memory messages
Like 0,20,0,20
Hear 0 indicates the no of messages stored in the sim card and 20 is for total no of messages which able to store on to the sim card.
AT+CREG=1
> It will display the message content...

Try this way, and tell what you are getting in your terminal...
 
  • Like
Reactions: PA3040

    PA3040

    Points: 2
    Helpful Answer Positive Rating
hi,

First of all Send "AT\r" to check your hardware and communication. if your module reply with "\r\nOK\r\n" then your communication ok.
Now send "AT+CPMS?\r" command to verify that there is any SMS store in Module, if it gives you that there is some SMS store in module, you can read it using "AT+CMGR=1\r". where 1 is memory index in your module.

Regards,
Ghanshyam
 

How you interface GSM modem to 8051 ? Did you use MAX232 ?

Post circuit.

No i dont use MAX 232 i had connected the Tx and Rx of 8051 MCU to the Rx and Tx of GSM modem , sending sms was worked in that way , but problem with reading sms



Regards
Deepak
 

Hi,

If you successfully send SMS, then it is very very easy task to read SMS,
First check there is any SMS pending in GSM module using "AT+CPMS?\r"
If yes, then read using "AT+CMGR=1\r".
Simple.....

Regards,
 

Hi to all when i give command AT+CPMS? it gives reply as follows
+CPMS: "SM",40,40,"SM",40,40,"SM",40,40
 

first try sending sms from ur modem while using it on hyperterminal, carefully note down all the instructions needed to send it, make exact copy of it in ur code , test ur microcontroller on hyperterminal too, both the codes should be same , then interface both the devices with each ohters
 

Hello everyone,
This is the same problem which I faced during my project and I could not rectify this mistake. I would like to know if any solution is found to this.

Normally the garbage character problem occurs when there is a mismatch in the baud rate settings.
But in the case of GSM, the sending works absolutely fine. Its only the reception part that is creating problem.
 

Hi to all when i give command AT+CPMS? it gives reply as follows
+CPMS: "SM",40,40,"SM",40,40,"SM",40,40


Hi Friend,

If your modem gives you above reply means your modem has 40 SMS store.

Now you can read all SMS one by one using "AT+CMGR=X\r" where X replace with SMS count like 1,2,3,....40.
and you get reply like below example,

Send : AT+CMGR=1\r

Received : \r\n+CMGR: "REC UNREAD","+919000700123",,"12/10/03,10:50:13+22"Here is your SMS message\r\n
Received : \r\nOK\r\n

Hope this is help you,

Regards,
 
Hi anyone can please tell me how to read the sms from gsm using 8051??
 

Connect your gsm modem or mobile to PC and issue at command AT+CMGF=1 and AT+CMGR=1. It will give some response. Take a screenshot of the Serial Terminal software showing the responses and post it. I will write a code.

https://www.edaboard.com/threads/290658/

Post your Serial interrupt routine.


Code C - [expand]
1
2
3
4
5
6
void recieve() interrupt 4     Function to recieve data serialy from RS232 
{
        msgIN[i++]=SBUF;
        RI=0;                // Reset the serial interrupt after recieving the byte
        msgIN[i] = '\0';   
}

 
Last edited:

Thank you Jayanth.....I am posting my code
Code:
#include <REGX52.H>
//LCD Declaration//
#define LCD P1
sbit rs=P2^0;
sbit rw=P2^1;
sbit en=P2^2;

void delayms(unsigned char);
void delayus(unsigned char);
void lcd_init();
void lcd_reset();
void lcd_cmd (char);
void lcd_data(unsigned char);
void lcd_str (unsigned char *);
void clear(void);
void tx0(unsigned char);
void delay_sms (unsigned int);
void ms_delay(unsigned int itime);
void SMSString(char*text) ;
void init();
void read_text(unsigned char * , unsigned char * , unsigned char *);

unsigned char j,abc;
unsigned char idata msg1[150];
unsigned char rec_no[20];
unsigned char time_date[20];


void serial () interrupt 4
{
msg1[abc]=SBUF;
abc++;
RI=0;
}


void main (void)
{
/*
if u do not want to check "OK" response after each AT command then
enable interrupt IE=0X90 ; after last AT command of  
SMSString( "AT+CMGR=1\r"); // AT command to read sms
so after that u recieve a no of bytes from modile if u disable it then u do not reieve
it even data comes

use a virtual terminal in Proteus
run a Proteus and right click on virtual terminal and click on option echo character display.
in Proteus there is no mobile model so u should enter text in hyper terminal to suppose gsm Modem is responding.
use serial receive interrupt to receive data
check here

*/
clear();
init();
lcd_init();

SMSString("AT\r"); // AT commands to initialize gsm modem
delay_sms(1000);

SMSString( "ATe0\r"); // turn off echo
delay_sms(1000);

SMSString( "AT&W\r"); // save settings
delay_sms(1000);

SMSString( "AT+CMGF=1\r"); // select text mode for sms
delay_sms(1000);

SMSString( "AT+CNMI=2,1,0,0,0\r"); // notification of new sms
delay_sms(1000);

SMSString( "AT+CMGR=1\r"); // AT command to read sms

IE=0X90;   // Enable serial interrupt
delay_sms(5000);

/* i get a response like this

// +CMGR: "REC READ" ,"+2347060580383","10/10/23,14:29:33+04"
// device1 off
// Ok. */

// read sms and store in buffer msg1

read_text(msg1,rec_no,time_date);
clear();
IE=0X00;     // Disable all interrupt
while(1);
}


void init(void)
{
j=0;
abc=0;
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 delay_sms (unsigned int count)
{
unsigned int i;                         // Keil v7.5a
    while(count) {
        i = 115;
                while(i>0) i--;
        count--;
}
}

void read_text( unsigned char *msg,unsigned char *no ,unsigned char *time)
{
unsigned char *temp;
temp=msg;
do
msg++;
while(*msg!='+');        
do
msg++;
while(*msg!='+');         //  reaching at no
do
*no++=*msg++;
while(*msg!='"');         // reaching at time
*no++='\0';
msg++;
msg++;
msg++;
do
*time++=*msg++;
while(*msg!='+');         // raching at message
*time='\0';
do
msg++;
while(*msg!='\n');
msg++;
do
*temp++=*msg++;
while(*msg!='\r');       // reaching at end of message
*temp='\0';

lcd_cmd(0x80);            // ist line address
lcd_str(rec_no);          // array having receipt no
lcd_cmd(0xC0);            // 2nd line address
lcd_str(time_date);       // array having date and time
lcd_cmd(0x94);            // 3rd line address
lcd_str(msg1);            // array having message
}


void lcd_init()
	{
	
	lcd_cmd(0x38);
	lcd_cmd(0x0F);
	lcd_cmd(0x01);
	lcd_cmd(0x06);
	lcd_cmd(0x80);
	}
	
void lcd_cmd(unsigned char value)
{
  LCD=value;
  rs=0;
  rw=0;
  en=1;
  ms_delay(1);
  en=0;
 }
 void lcd_data(unsigned char value)
 { 
   LCD=value;
   rs=1;
   rw=0;
   en=1;
   ms_delay(1);
   en=0;
 }


 void ms_delay(unsigned int itime)
{
  unsigned int i,j;
  for(i=0;i<itime;i++){
		
  for(j=0;j<1200;j++);
	}
}
void clear(void)
{
unsigned char a;
for(a=0;a<100;a++)
msg1[a]=0x00;
}

void lcd_str (unsigned char *str)
{
        while(*str){
                lcd_data(*str++);
        }
}

[COLOR="silver"][SIZE=1]- - - Updated - - -[/SIZE][/COLOR]

i am also working on this code  but also getting garbage value 

#include <reg52.h>     
#include <stdio.h>
                        
//Delay Functions Declarations	********************************
void ms_delay(unsigned int itime)
{
  unsigned int i,j;
  for(i=0;i<itime;i++){
		
  for(j=0;j<1200;j++);
	}
}	
void delay()
{
	int i,j;
	for(i=0;i<1000;i++)
  for(j=0;j<5000;j++);
}
// Delay functions declaration********************************									

			
//LCD Function Declarations------------------------
sbit rs=P2^0;
sbit rw=P2^1;
sbit en=P2^2;
#define LCD P1
void lcd_cmd(unsigned char value)
{
  LCD=value;
  rs=0;
  rw=0;
  en=1;
  ms_delay(1);
  en=0;
 }
void lcd_data(unsigned char value)
 { 
   LCD=value;
   rs=1;
   rw=0;
   en=1;
   ms_delay(1);
   en=0;
 }
void string_lcd (unsigned char* ptr)
 { 
   unsigned int h,j=0;
   while(*ptr)
   {
      h++;
	  if(h<15)
	  {
	    lcd_data(*ptr++);
	  }
	  if(h>=15)
	  {
	    lcd_cmd(0xc0+j);
		lcd_data(*ptr++);
		j++;
	  }
	  // *(ptr++);
	  }
	}
	
void lcd_init()
	{
	
	lcd_cmd(0x38);
	lcd_cmd(0x0F);
	lcd_cmd(0x01);
	lcd_cmd(0x06);
	lcd_cmd(0x80);
	}
// LCD Functiond End----------------------------
//Gsm Functions	
void String_Gsm(unsigned char*);	
void Write_Gsm(unsigned char);	
void Read_Gsm(unsigned int);
	
//	
	
unsigned char mysms;     
unsigned char buffer[20];	
void main (void) 
{       
	unsigned char at[]="at";
	unsigned int i=0;	
	TMOD = 0x20;    
	SCON = 0x50;    
	TH1  = -3;    
	TR1  = 1;
	TI=1;
	lcd_init();
	string_lcd("Testing GSM");
	lcd_cmd(0xc0);
	string_lcd("Reading SMS");
	ms_delay(500);
	lcd_cmd(0x01);
	lcd_cmd(0x06);
	lcd_cmd(0x80);
	
                 String_Gsm("at");
	ms_delay(2);
	Write_Gsm(0x0d);
	ms_delay(1);
	read_Gsm(2);
	ms_delay(50);
	lcd_cmd(0x01);
	String_Gsm("at+cmgf=1");
	ms_delay(10);
	Write_Gsm(0x0d);
	ms_delay(1);
	read_Gsm(2);
	ms_delay(50);
	lcd_cmd(0x01);
	
               String_Gsm("at+cnmi=2,1,0,1,0");
	ms_delay(10);
	Write_Gsm(0x0d);
	ms_delay(1);
	read_Gsm(2);
	ms_delay(50);
	lcd_cmd(0x01);
	String_Gsm("at+cmgr=1");
	ms_delay(2);
	Write_Gsm(0x0d);
	ms_delay(1);
	read_Gsm(20);
	
}

void String_Gsm(unsigned char *s)
{
		while(*s)
		Write_Gsm(*s++);
}

void Write_Gsm(unsigned char c)
{
	SBUF=c;
	lcd_data(c);
	while(TI==0);
	TI=0;
	ms_delay(2);
}

void read_Gsm(unsigned int count)
{
	int i=0;
	while(count>0)
	{		
		while(RI==0);
		while(RI==0);
		while(RI==0);
		if(RI==1)
		{
				i=0;
				buffer[i]=SBUF;
				lcd_data(buffer[i]);
				RI=0;
			i++;
		}
		if(count==0)break;
		count --;
	}	
}
void serial_intr(void) interrupt 4    //interrupt service routine for serial interrupt
{
if(TI==1) 			//if transmit interrupt, clear TI
		{
		 TI=0;
		} 
	if(RI==1) 			//if receive interrupt
	{
			mysms=SBUF;
			lcd_data(mysms);
			RI=0;
	}  
}
 
Last edited by a moderator:

Hi when i connected the GSM module serially to PC on hyper terminal it shows as following ....sorry am unable to take screenshot ...

AT+CMGR=4

+CMGR: "REC READ","TD-610401","","12/08/24,10:52:41+22"

420 Mins for 15days!! 300 ALL Mins+120 LOCAL T2T mins as bonus on RC120.Hurry! o
ffer valid only on 24th,25th & 26thAug12.Extra benefits will credited in 72hours

OK
 

420 Mins for 15days!! 300 ALL Mins+120 LOCAL T2T mins as bonus on RC120.Hurry! o
ffer valid only on 24th,25th & 26thAug12.Extra benefits will credited in 72hours

is the actual message.
 

Hi jayanth ..yes thats the actual message
 

Issue command AT+CMGR=1, AT+CMGR=2, AT+CMGR=5 and take a screenshot of the response by pressing PrintScreen button on keyboard and then pasting the image from clipboard to Paint. Post the Screenshot.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top