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.

Problem receiving SMS from GSM

Status
Not open for further replies.

Twisted_transistor

Member level 1
Member level 1
Joined
Sep 13, 2012
Messages
32
Helped
2
Reputation
4
Reaction score
1
Trophy points
1,288
Visit site
Activity points
1,478
Problem receiving SMS from GSM[HELP]

Hi, I've connected my SIM300 to LPC2148 via RX, TX & GND lines and successfully transmitted SMSs. Now I've written a code to do the following:
-Initialise the GSM module and wait for an SMS to arrive at the SIM
-Wen an SMS is received, the LPC2148 receives an indication in the form of a +CMTI string
-We extract the location of the SMS on the SIM and read the SMS
-This same SMS is den sent to another number indicated by ########## in the code

But on burning the code it was found that blank messages are being sent to the number ########## instead of the actual received SMS.

Can someone please tell me whats wrong in my code:

Code:
#include<lpc214x.h>
extern unsigned char cmgf[]="AT+CMGF=1";	                        //Text format in GSM modem
extern unsigned char cmgsh[]="AT+CMGS=\"+############\"";          	//Mobile number to which the msg is sent

unsigned char cmgr[]="AT+CMGR=";
unsigned char newmsg=0x00;
unsigned char msgid;

void txu1(unsigned char data)				  //Transmit a byte of data through UART1
{
while(!(U1LSR & 0x20));
  U1THR=data;
 }

unsigned char rxu1()
{
unsigned char p;
while ((U1LSR&0x01)!=1);
p=U1RBR;
return p;
}

void sendstring(unsigned char *p)			 //Sends a string of data through UART1
{
while(1)
{
if(*p=='\0') break;
txu1(*p++);
}
}


void delay()							  //delay function
{
int i,j;
for(i=0;i<60000;i++)
for(j=0;j<200;j++);
}


void readmsg()
{
int i;
unsigned char p[21];
sendstring(cmgr);
txu1(msgid);
txu1(0x0D);
txu1(0x0A);
for(i=0;i<6;i++)
p[i]=rxu1();
p[6]='\0';


IO1SET=0x00070000;
sendstring(cmgf);
txu1(0x0D);										// equivalent of 
txu1(0x0A);										//	 enter key
delay();
sendstring(cmgsh);
txu1(0x0D);
txu1(0x0A);	
delay();
sendstring(p);
txu1(0x1A);
delay();
txu1(0x1A);
IO1CLR=0x00070000;
} 



void uart1_irq() __irq
{					  //ISR if anything is recieved in UART1
unsigned char p[12];
unsigned char q;
int i;

q=U1RBR;
if(q=='+')
{
for(i=0;i<11;i++)
{
p[i]=U1RBR;
}
msgid=p[10];
p[11]='\0';

IO1SET=0x00020000;
newmsg=0x01;
}

VICVectAddr=0;
}

void init()								 //Initialization of UART0,UART1 and ISR
{
U1LCR=0x83;
U1DLL=0x62;
U1DLM=0x00;
U1LCR=0x03;
U1IER=0x01;
U1FCR=0X07;
VICIntSelect&=0xffffff7f;
VICVectAddr2=(unsigned int)uart1_irq;
VICIntEnable|=0x00000080;
VICVectCntl2=0x20|7; 
}


int main()
{ 
VICIntEnClr=0x00000080;
PINSEL0=0x00050005;
PINSEL1=0x00000000;
PINSEL2=0x00000000;
init();

IO1DIR=0xFFFF0000;

sendstring("ATe0\r\n");
delay();

sendstring("AT+CNMI=3,1,0,0,0\r\n");
delay();

IO1SET=0x00010000;
U1IER=0x01;

while(newmsg==0x00);
newmsg=0x00;
readmsg();
}



Any help will be greatly appreciated.

Muito obrigada:)
 
Last edited:

Re: Problem receiving SMS from GSM[HELP]


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
sendstring(&cmgr);
sendstring(&cmgsh);
sendstring(&cmgf);
sendstring(&p);
 
unsigned char atcmd1[] = "ATe0\r\n"
unsigned char atcmd2[] = "AT+CNMI=3,1,0,0,0\r\n"
 
sendstring(&atcmd1);
delay();
sendstring(&atcmd2);

 
Last edited:

Re: Problem receiving SMS from GSM[HELP]

Hmmm.. Well do you mean to say I should put the ampersand sign while sending the comands?
Coz my codes have worked fine before without putting the ampersand sign.
And, besides, when we pass an array the starting address of the array get passed automatically to the function right?

- - - Updated - - -

Hmmm.. Well do you mean to say I should put the ampersand sign while sending the comands?
Coz my codes have worked fine before without putting the ampersand sign.
And, besides, when we pass an array the starting address of the array get passed automatically to the function right?
 

Re: Problem receiving SMS from GSM[HELP]

No. It is not putting ampersand. See the function prototype of function sendstring(). The argument is a pointer and pointer expects left value or address of other variable. So you have to pass the address of the array which holds the string.
 

Yes..I see what you mean. But it works fine like that.
Coz after modifying the code a little, the programmed number ########## now receives string p correctly. i.e it receives the string:- CMTI: "SM",2
Where "2" is the location in the SIM memory where the received SMS is stored. But the problem now is that I still cannot read the received SMS from that location.

The corrected code is as follows:

Code:
#include<lpc214x.h>
extern unsigned char cmgf[]="AT+CMGF=1";	                        //Text format in GSM modem
extern unsigned char cmgsh[]="AT+CMGS=\"+############\"";          	//Mobile number to which the msg is sent
 
unsigned char cmgr[]="AT+CMGR=";
unsigned char newmsg=0x00;
unsigned char msgid;
 
void txu1(unsigned char data)				  //Transmit a byte of data through UART1
{
while(!(U1LSR & 0x20));
  U1THR=data;
 
}
 
unsigned char rxu1()
{
unsigned char p;
while ((U1LSR&0x01)!=1);
p=U1RBR;
return p;
}
 
void sendstring(unsigned char *p)			 //Sends a string of data through UART1
{
while(1)
{
if(*p=='\0') break;
txu1(*p++);
}
}
 
 
void delay()							  //delay function
{
int i,j;
for(i=0;i<60000;i++)
for(j=0;j<200;j++);
}
 
 
void readmsg()
{
int i;
unsigned char p[60];
unsigned char q[7];
sendstring(cmgf);
txu1(0x0D);										// equivalent of 
txu1(0x0A);										//	 enter key
delay();
sendstring(cmgr);
txu1(msgid);
txu1(0x0D);
txu1(0x0A);
for(i=0;i<58;i++)
p[i]=U1RBR;
 
for(i=0;i<6;i++)
q[i]=U1RBR;
q[6]='\0';
 
IO1SET=0x00070000;
sendstring(cmgf);
txu1(0x0D);										// equivalent of 
txu1(0x0A);										//	 enter key
delay();
sendstring(cmgsh);
txu1(0x0D);
txu1(0x0A);	
delay();
sendstring(q);
txu1(0x1A);
delay();
txu1(0x1A);
IO1CLR=0x00070000;
} 
 
 
 
void uart1_irq() __irq
{					  //ISR if anything is recieved in UART1
unsigned char p[13];
unsigned char q;
int i;
 
q=U1RBR;
if(q=='+')
{
for(i=0;i<12;i++)
{
p[i]=rxu1();
}
msgid=p[11];
p[12]='\0';
 
sendstring(cmgf);
txu1(0x0D);										// equivalent of 
txu1(0x0A);										//	 enter key
delay();
sendstring(cmgsh);
txu1(0x0D);
txu1(0x0A);	
delay();
sendstring(p);
txu1(0x1A);
delay();
txu1(0x1A);
 
IO1SET=0x00020000;
newmsg=0x01;
}
VICVectAddr=0;
}
 
void init()								 //Initialization of UART0,UART1 and ISR
{
U1LCR=0x83;
U1DLL=0x62;
U1DLM=0x00;
U1LCR=0x03;
U1IER=0x01;
U1FCR=0X07;
VICIntSelect&=0xffffff7f;
VICVectAddr2=(unsigned int)uart1_irq;
VICIntEnable|=0x00000080;
VICVectCntl2=0x20|7; 
}
 
 
int main()
{ 
VICIntEnClr=0x00000080;
PINSEL0=0x00050005;
PINSEL1=0x00000000;
PINSEL2=0x00000000;
init();
 
IO1DIR=0xFFFF0000;
 
sendstring("ATe0\r\n");
delay();
 
sendstring("AT+CNMI=3,1,0,0,0\r\n");
delay();
 
IO1SET=0x00010000;
U1IER=0x01;
 
while(newmsg==0x00);
newmsg=0x00;
 
readmsg();
}

Can u pls tell me whre I'm going wrong in reading the SMS from the SIM memory?

Thanks alot for your help & for taking interest in my problem:)
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top