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

Fri Nov 15 2019, 08:19 AM
Allison Wink
Want to submit your business on 1000's of Advertising sites monthly? For a small monthly payment you can get virtually unlimited traffic to your site forever!For details check out: http://www.submitmyadnow.tech
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,
ExperimenterUK
Mon Aug 05 2019, 07:09 PM
@Ismail ..post in forum, give details
Mon Aug 05 2019, 04:33 PM
Ismail balghmi
Hello. Please I won't download
ExperimenterUK
Wed Jul 24 2019, 12:47 AM
@BUSTER123 Please post in the forum
Tue Jul 23 2019, 06:13 PM
BUSTER123
hello! newbie here. i am kind of a guy who hates using ready - made existing libraries, so this helped a lot as i was trying to control and write to a character lcd display. however, i can't figure out how to set the cursor position. for example, i want to set it to the 5th column in the first row, so position 5. so according to the table, i am sending 10000101 on the 8 data lines of the lcd (register select pulled low). the cursor does not move there however. and i cant move the cursor left or right too. is it something wrong that i am doing? thank you.
ExperimenterUK
Thu Jul 11 2019, 07:55 PM
@ramos https://www.theengineeringprojects.com/2017/09/l298-motor-driver-library-proteus.html

Downloads

Comments

Casmir
Wed Nov 13 2019, 06:25 AM
DeepakBGattani
Mon Nov 11 2019, 01:31 PM
Jeanbusatta
Sun Nov 10 2019, 04:42 AM
mdayaz
Sat Nov 09 2019, 03:41 PM
baoyen123
Fri Nov 08 2019, 10:06 AM
xiwang
Fri Nov 08 2019, 07:28 AM
ilylily07
Tue Oct 15 2019, 04:32 PM
hientran123
Tue Oct 15 2019, 02:27 AM

Online

Guests: 206, Members: 0 ...

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

Members: 38103
Newest member: Casmir
Forum Activity
Jeanbusatta Avatar
Posted By Jeanbusatta
Sun Nov 10 2019, 04:43 AM
ty, really needed it
ExperimenterUK Avatar
Posted By ExperimenterUK
Tue Oct 22 2019, 05:18 AM
wimac Avatar
Posted By wimac
Mon Oct 21 2019, 09:18 AM
I’ve been following this thread and looking at the...
s_dinesh40@yahoo.com Avatar
Posted By [email protected]
Sun Oct 20 2019, 03:09 PM
s_dinesh40@yahoo.com Avatar
Posted By [email protected]
Sun Oct 20 2019, 03:02 PM
sir, when i on display ,sometime 3rd display is no...
s_dinesh40@yahoo.com Avatar
Posted By [email protected]
Sun Oct 20 2019, 02:53 PM
sir, when i on display ,sometime 3rd display is no...
ExperimenterUK Avatar
Posted By ExperimenterUK
Sun Oct 20 2019, 12:21 AM
Your code seems okay on my simulationTry my code o...
s_dinesh40@yahoo.com Avatar
Posted By [email protected]
Sat Oct 19 2019, 07:13 PM
please find video attachment. 3rd & 4th displa...
s_dinesh40@yahoo.com Avatar
Posted By [email protected]
Sat Oct 19 2019, 07:05 PM
sir, 3rd and 4th dot matrix display flickering, ...
ExperimenterUK Avatar
Posted By ExperimenterUK
Fri Oct 18 2019, 09:18 PM
Hopefully you understand some of the program.Which...