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.

[51] Sms receiving and display on lcd

Status
Not open for further replies.

Azzy anxious

Junior Member level 2
Junior Member level 2
Joined
Jan 28, 2014
Messages
23
Helped
1
Reputation
2
Reaction score
1
Trophy points
3
Activity points
161
Hi
I am working on a project in which i am trying to display the sms on 16x2 lcd....

i have studied at commands and able to read sms bt only saved sms....

i am unable to read new msg....how can i know new sms indication...

and i want to know about cnmi=2,2,0,0,0 according to me i think it is a new msg indication command bt i just want to display the new msg.......
 

@Azzy,

Pls use the below said command.

AT+CNMI=3,1,2,1,1

You will get the new message indication in your UART...Once this message is captured in the UART just display the same in the LCD...
 

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,2,0,0,0\r"); // notification of new sms
delay_sms(1000);

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

I m usig above codes

- - - Updated - - -

i m using same code bt i m nt unable to read new msg as i m doing this in a while loop
 

@Azzy,

1. Use the AT Command - AT+CNMI=3,1,2,1,1
2. Do not use a while loop.

Instead follow the below method to capture the new message notification:

1. Initialise all the AT commands before while loop except AT+CMGR=1.
2. Initialise the UART as interrupt.
3. Declare a buffer of 128 bytes or 256 bytes.
4. Capture the data from the uart interrupt and store in the buffer said in point 3.
5. Validate this buffer inside the WHILE LOOP.
6. The validation of the buffer inside the WHILE LOOP should be done if the received data in the UART interrupt contains <Enter>.
7. If the received data matches the new message indication, then send AT+CMGR=1 and read the message and store the message content in the above buffer. (Before doing this point clear the buffer)
8. Now display in the lcd.

Hope this helps.
 

Use "AT+CNMI=2,1\r" for SIM900. It works for me.
 

I m using sim300........

- - - Updated - - -

Hiiiii,
I have changed my program as-
PHP:
void main (void)
{
rw=0;
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);

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

SMSString( "AT+CNMI=2,2,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);



// read sms and store in buffer msg1

read_text(msg1,rec_no,time_date);
clear();
IE=0X00;     // Disable all interrupt
delay_sms(1000);
SMSString( "AT+CMGD=1\r"); 
delay_sms(1000);
//while(1);
} }
Using this program Iam able to receive the msg......
but sometimes the msg deleted without showing it on lcd.......
Plz help me and suggest e to overcome from this......
I am trying to achieve this-
1. receive the msg
2. read received msg
3. delete the received msg
 
Last edited:

You have to issue "AT+CMGF=1\r" and AT+CNMI=2,1\r" only once before while(1) loop. Then you have to use Serial receive interrupt to receive new msg notification. After you receive the notification you should send "AT+CMGR=x\r" depending upon the msg index obtained from +CMTI: "SM", x response. After you read and display the SMS you can delete the SMS using AT+CMGD=x\r where x is again the SMS index to be deleted.

Use strstr() to see if "+CMTI: "SM"," is received. Extract index of SMS from this response string.
 
Your code should be like the below one.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
void main (void) 
{ 
rw=0; 
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,2,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); 
 
while(1) 
{ 
  //Check the recvdbuffer from interrupt has "0x0A" && "0x0D"...
  {
     //check again if the buffer contains "+CMTI:" and if contains
     {
        //Clear the recvd buffer in the interrupt
        //read the new sms using AT+CMGR=1
        //Check the content if needed
        //delete the sms 
       //clear the recvd buffer
     }
   }
 } 
}



Your interrupt routine should as shown below. Declare a buffer of size buff[256]..



Code C - [expand]
1
2
3
4
void Serial_Interrupt()
{
   buff[counterbuff++] = (USART1_ReceiveData());
}



Hope this helps you...
 
Last edited by a moderator:
thanks for replying again.....
plz make me clear this line.....

//Check the recvdbuffer from interrupt has "0x0A" && "0x0D"...

how can i check this that it is receiving 0x0A or 0x0D......

I am also using buffer to store the received msg.....

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

Code:
if (msg1[abc] == 0x0A) {then do something};
abc++;

Cheers
 

Thanks Batang for reply.....
I have tried this as.....
PHP:
void main (void)
{
rw=0;
clear();
init();
lcd_init();

SMSString("AT\r"); 
delay_sms(1000);

SMSString( "ATe0\r"); 
delay_sms(1000);

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

SMSString( "AT+CMGF=1\r");
delay_sms(1000);

SMSString( "AT+CNMI=2,1,0,0,0\r");
delay_sms(1000);

SMSString( "AT+CMGR=1\r"); 

IE=0X90;  
delay_sms(5000);

while(1)
{

if (msg1[abc] == 0x0A)
{
SMSString( "AT+CMGR=1\r");
delay_sms(1000);
read_text(msg1,rec_no,time_date);
clear();
IE=0X00; 
delay_sms(1000);
SMSString( "AT+CMGD=1\r"); 
delay_sms(1000);
} }  }

But no msg is received under this condition...
 

Personally I would set a flag in the IRQ routine that is true when 0x0A (or 0x0D) is received and then test the flag in the main program loop. Remember to mark the flag as volatile otherwise your compiler might whittle it away.

Also in your code you are checking the second storage location for the message i.e. AT+CMGR=1 but your message could be in the first location i.e. AT+CMGR=0

Also be aware that there are several CR/LF characters in a received SMS message as per the below example.

Code:
+CMGR: "REC READ","+60120000000",,"14/05/16,00:12:05+32"
This is the message

Cheers.
 

Thanks Batang for reply.....
Sir
i m newbie i do'nt knw how to set a flag is there ny simplex way 4 this plzzzzzzzzzz.......
 

Flag exmaple

Code:
volatile uint flag = 0;   // Declare flag

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

void main (void) 
{ 

your code goes here

if( flag == 1) {do something; flag = 0;}

and here

}

Cheers
 
thanks 4 help

Bt sir why we are enabling and disabling IE here
 

enabling and disabling IE here

I am not sure what you mean.
 

I mean how IE(Interrupt Enable) effects on data receiving.......
and role of it.....???
 

In my code example I only setting flag, the rest of the code was from your example.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top