Discussion in "Embedded GSM Development" started by    kirangowle    Nov 20, 2010.
Wed Dec 01 2010, 07:16 AM
#31
Hi mojaka,

Thanks for ur reply

Now how can i send index no(int data) to modem through same SMSString()function can i do.
Wed Dec 01 2010, 07:27 AM
#32
hi kirangowle
i think int will not come because as u said that sim300 has 25 msg memory so index will not be more than 255
as index = atoi(&array[12]); will convert ascii into int so its better u not use this because when u send again it to modem then u again need it to make ascii
if(strncmp(array, "+CMTI", 5) == 0){
    //Yes its a new message ..
    //Now lets read the index
    //we first have to truncate the array... to use string functions
    array[14] = '\0'; //coz array[12] and array[13] may contain your index
SMSString( "AT+CMGR=");
tx0(array[12]);
SMSString( "\r");


[ Edited Wed Dec 01 2010, 07:32 AM ]
 kirangowle like this.
Wed Dec 01 2010, 10:44 AM
#33
Hi
From the guidance of mojaka and ajay, i have modified the code
 
void main ()
{

clear();
lcdinit();
lcdcmd(0x80);
lcddata('K');
delay(10);
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);

SMSString( "AT+CMGF=1\r"); // select text mode for sms
delay(50);
SMSString( "AT+CNMI=2,1,0,0,0\r"); // notification of new sms
delay(10);
 
//New msg indication.
// +CMTI: "SM",3
while(1)
{
clear();
IE=0X90;   // Enable serial interrupt
delay(10);
read_notification(msg1);
IE=0x00;
}
}


And this is the function to read the notification of new msg.

 
void read_notification(unsigned char *msg)
{
unsigned char array[15],i,index_no;
i=0;
do
{
       msg++;
	i++;
}while(*msg!='+' && i!=15); // to check for first '+'.
i=0;

do
{
     array[i]=*msg++;
     i++;
}while(*msg!='\n' && i!=15);      // Check for new line.

if(strncmp(array, "+CMTI", 5) == 0)
{
	array[14] = '\0';
	IE=0x00;
	lcdcmd(0x80);
lcdstr("NEW MSG");// Just for indication.
	delay(50);
	SMSString("AT+CMGR=");
	tx0(array[12]);
	SMSString("\r");
	IE=0x90;
	delay(80);
	read_text(msg1,rec_no,time_date);
	delay(100);
}
return;
}



The above code works partly.
It reads the new msg and displays correctly on LCD sometimes, and sometimes it doesnt goes into the loop itself.
I think msg should be sent at some particular time so that 8052 can able to read.
Wed Dec 01 2010, 11:52 AM
#34
do little modification here and try again
unsigned char a;  // should be global
clear();
SMSString( "AT+CMGF=1\r"); // select text mode for sms
delay(50);
while(1)
{
SMSString( "AT+CNMI=2,1,0,0,0\r"); // notification of new sms
IE=0X90;   // Enable serial interrupt
delay(100);
//New msg indication.
// +CMTI: "SM",3

a=read_notification(msg1);
if(t==1)     // means new message arrive and need to display
{
t=0;
SMSString("AT+CMGR=");
        tx0(a);
        SMSString("\r");
        IE=0x90;
        delay(1000);
        read_text(msg1,rec_no,time_date);
}
IE=0x00;
clear();
delay(100);
}
}



unsigned char read_notification(unsigned char *msg)
{
unsigned char array[15],i,index_no;
i=0;
do
{
       msg++;
        i++;
}while(*msg!='+' && i!=15); // to check for first '+'.
i=0;

do
{
     array[i]=*msg++;
     i++;
}while(*msg!='\n' && i!=15);      // Check for new line.

if(strncmp(array, "+CMTI", 5) == 0)
{
        array[14] = '\0';
        IE=0x00;
        lcdcmd(0x80);
lcdstr("NEW MSG");// Just for indication.
        delay(50);
return ((array[12]);
}
}
        


do some more experiments try coding in different methods
 kirangowle like this.
Thu Dec 02 2010, 09:39 AM
#35

Hi

I tried in different combination's its coming, but some time unable to read the new msg notification. So i enabled the serial int all the time without disabling it, then also no desired result.

 
while(1)
{
SMSString( "AT+CNMI=2,1,0,0,0\r"); // notification of new sms
delay(10);
IE=0X90;   // Enable serial interrupt
delay(100);
read_notification(msg1);
clear();
delay(50);


I think i am doing some wrong. what abt the clear() function,
If suppose new msg indication occurs when the processor is in clear fn.
then the content of msg1[] would be different from "+CMTI".

 
void read_notification(unsigned char *msg)
{
unsigned char array[15],i;
i=0;
//clear();
IE=0x90;
do
{
	msg++;
	i++;
	lcdcmd(0x80);
	lcdstr("InLoop1");
}while(*msg!='+' && i!=5); // to check for first '+'.
i=0;

do
{
      array[i]=*msg++;
      i++;
}while(*msg!='\n' && i!=15);      // Check for new line.

if(strncmp(array, "+CMTI", 5) == 0)
{
	array[14] = '\0';
	IE=0x00;
	lcdcmd(0x80);
	lcdstr("NEW MSG");
	delay(50);
	SMSString("AT+CMGR=");
        tx0(array[12]);
        SMSString("\r");
        IE=0x90;
        delay(100);
        read_text(msg1,rec_no,time_date);
}


Thu Dec 02 2010, 09:46 AM
#36
Approx. Out of 10 msgs only 2 msgs are read(displayed).
Thu Dec 02 2010, 01:51 PM
#37
hi kirangowle
change a little here
while(1)
{
SMSString( "AT+CNMI=2,1,0,0,0\r"); // notification of new sms
IE=0X90;   // Enable serial interrupt
delay(500);
read_notification(msg1);
clear();
delay(50);

If suppose new msg indication occurs when the processor is in clear fn.
then the content of msg1[] would be different from "+CMTI".


tell me 1 thing is modem response automatically when new message come or 1st we send AT command then it response mean every time is first we issue a command to it that notify me or just we issue it once in start up after that it response automatically as new message come clear my this point
if it response automatically then it=f it is in clear function then error expected but if it response only when AT command issue then clear will not disturb it
Thu Dec 02 2010, 03:42 PM
#38
The way you're reading SMS is obviously not a good method and there are 90% chances of loosing an SMS.

Best way...
check for new message indication in interrupt itself.

e.g.

//You need two variables and a constant, one for storing constant string,
//second for an index pointer and a buffer to store recieved data
unsigned char code Response[] = "+CMTI";
unsigned char MyBuff[15], i = 0;
//we can also have a flag for new message
bit NewMessage = 0;

//consider this ISR function
//assuming ch is read character from SBUF
if((ch == Response[i]) || (i >
 4)){
	//if received character is there in Response or i is >
 4 which means
	// you already have the right string...
	if(ch != 0x0D) { // 0x0D means data received..
		//Store received data
		MyBuff[i++] = ch;
	} else {
		//seems like we have recieved our data
		//Now stop and indicate that new message has received
		MyBuff[i] = '\0';
		NewMessage = 1;
		
		//do not forget to reset i :)
		i = 0; // no more errors..
	}
} else {
	//there is a miss match
	//reset counter
	i = 0;
}

//Now in main loop you can just wait for New message flag

while(!NewMessage);
NewMessage = 0;

//Parse MyBuff, get the index and read message :)
 kirangowle like this.
Tags reading sms from gsm modemreading sms using 8051gsm modem read sms codegsm modem sms reading using interrupt
Thu Dec 02 2010, 03:55 PM
#39
hi Ajay Bhargav
ur coding skills r great
i always like ur way of coding
u do a complex with simple one
i glad that i am here with this lovely company of experts
Fri Dec 03 2010, 07:49 AM
#40
@ Mojaka,

tell me 1 thing is modem response automatically when new message come or 1st we send AT command then it response mean every time is first we issue a command to it that notify me or just we issue it once in start up after that it response automatically as new message come clear my this point



without sending the AT commands Modem sends new msg indication.

@ Ajay,
Like this u wanna me do.
void serial () interrupt 4
{
	unsigned char ch;
	while(RI==0);
	ch=SBUF;

	if((ch == Response[k]) || (k >
 4)){
        //if received character is there in Response or k is >
 4 which means
        // you already have the right string...
        if(ch != 0x0D) { // 0x0D means data received..
                //Store received data
                MyBuff[k++] = ch;
        } else {
                //seems like we have recieved our data
                //Now stop and indicate that new message has received
                MyBuff[k] = '\0';
                NewMessage = 1;
               	//do not forget to reset k :)
                k = 0; // no more errors..
        }

	} 
else {
       [blockquote] msg[abc]=ch;// Not the msg indication, then store the msg.[/blockquote]
	abc++;
        k = 0;
}
RI=0;

}


In this, why we have to check for carriage return(0x0D).

 hiabcwelcome like this.

Get Social

Information

Powered by e107 Forum System

Conversation

Sat Feb 01 2020, 10:12 AM
Pearl Olin
Hello,
Wed Jan 22 2020, 06:16 PM
MINU CHAUDHARY
I m getting errors while simulation process during interfacing socket output and lcd... Can i get the report of ur project which is same as us.
Tue Jan 14 2020, 07:08 AM
shubham kharade
when i am trying to simulate the program in Proteus 8 professional, I am getting some errors as cannot find module file dhtxx.md can u help me
Tue Dec 17 2019, 01:44 PM
Devangi
hello..i am programming industrial timer using 8051 with 24lc64 eeprom. i have query in storing the 3 diff value in eeprom with enter button. can anyone share c code ?
Tue Dec 17 2019, 10:30 AM
Andrius
Hello. Can anyone share the code in Bascon and scheme in Proteus?
Thu Nov 21 2019, 12:30 PM
raj2555
how to interface 8051 microcontroller with NRF24L01+ module
ExperimenterUK
Sat Oct 12 2019, 10:23 PM
Log in.. then post your code in the 8051 forum
Sat Oct 12 2019, 10:18 AM
Bhadra Sajikumar
i am doing a countdown timer with 8051 for my project, unfortunately our professor had to take a leave of absence before he could teach us most of it.. can someone explain the .asm code of it for me?
Mon Sep 23 2019, 07:37 AM
Nathaniel
I am doing a project for my schools wireless security system with cameras,sensors and spot lights using 8051 micro controller, could you help me out with the design and its source code.
Wed Sep 18 2019, 08:48 PM
Caryn Kover
Thank you for your time,

Downloads

Comments

sarrahjuzar
Wed Feb 19 2020, 09:13 AM
arun.sapro
Wed Feb 12 2020, 04:47 PM
prathmiyer
Tue Feb 11 2020, 11:12 AM
Just4Fun
Sat Feb 01 2020, 01:29 PM
Deepkumar
Thu Jan 30 2020, 03:52 PM
wounder
Sat Jan 25 2020, 12:09 PM
brucewilliams20
Thu Jan 23 2020, 11:47 AM
Nippy56
Sun Jan 19 2020, 02:13 AM

Online

Guests: 52, Members: 0 ...

most ever online: 182184
(Members: , Guests: 182184) on 06 Aug 2010: 05:37 AM

Members: 38123
Newest member: sarrahjuzar
Forum Activity
ExperimenterUK Avatar
Posted By ExperimenterUK
Fri Feb 21 2020, 10:05 PM
ajay_bhargav Avatar
Posted By ajay_bhargav
Fri Feb 21 2020, 09:45 AM
Yes you can do that.1. Create a channel @Thingspea...
ananyagupta Avatar
Posted By ananyagupta
Thu Feb 20 2020, 08:58 AM
With regards to the particular characters sent to ...
sarrahjuzar Avatar
Posted By sarrahjuzar
Wed Feb 19 2020, 09:24 AM
I have a gsm module sim900a and dht22 connected to...
ExperimenterUK Avatar
Posted By ExperimenterUK
Tue Feb 18 2020, 09:52 PM
figureyang Avatar
Posted By figureyang
Tue Feb 18 2020, 09:59 AM
figureyang Avatar
Posted By figureyang
Tue Feb 18 2020, 09:50 AM
wounder Avatar
Posted By wounder
Mon Feb 10 2020, 08:32 AM
From below sample code for nuvoton 8051 timer0 mod...
Just4Fun Avatar
Posted By Just4Fun
Sat Feb 01 2020, 02:20 PM
If you want to use a CH55x MCU there isn't any adv...
Just4Fun Avatar
Posted By Just4Fun
Sat Feb 01 2020, 01:51 PM
Hi all,I was curious to try out the CH552 MCU (805...