Discussion in "Embedded GSM Development" started by    kirangowle    Nov 20, 2010.
Wed Dec 01 2010, 12:46 pm
#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, 12:57 pm
#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, 01:02 pm ]
 kirangowle like this.
Wed Dec 01 2010, 04:14 pm
#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, 05:22 pm
#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, 03:09 pm
#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, 03:16 pm
#36
Approx. Out of 10 msgs only 2 msgs are read(displayed).
Thu Dec 02 2010, 07:21 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, 09:12 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, 09:25 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, 01:19 pm
#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

Downloads

Comments

Bobbyerilar
Thu Mar 28 2024, 08:08 am
pb58
Thu Mar 28 2024, 05:54 am
Clarazkafup
Thu Mar 28 2024, 02:24 am
Walterkic
Thu Mar 28 2024, 01:19 am
Davidusawn
Wed Mar 27 2024, 08:30 pm
Richardsop
Tue Mar 26 2024, 10:33 pm
Stevencog
Tue Mar 26 2024, 04:26 pm
Bernardwarge
Tue Mar 26 2024, 11:15 am