Twisted_transistor
Member level 1
- Joined
- Sep 13, 2012
- Messages
- 32
- Helped
- 2
- Reputation
- 4
- Reaction score
- 1
- Trophy points
- 1,288
- 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:
Any help will be greatly appreciated.
Muito obrigada
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: