GSM Modem - Read SMS example using interrupts
Discussion in "Embedded GSM Development" started by Ajay Bhargav Feb 5, 2013.
Tue Feb 05 2013, 02:40 pm
//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 :)
After you go through this pseudo code.. Please read complete discussion in this thread:
http://www.8051projects.net/t41321-p30/embedded-gsm-development/gsm-modem-8051.htm#post_42097
kirangowle like this.
Tags reading sms from gsm modemreading sms using 8051gsm modem read sms codegsm modem sms reading using interrupt
Thu Jan 15 2015, 04:13 pm
Hi Ajay ,
I am trying to implement your logic for "Reading SMS from SIM900A GSM Module ". But
Could not succeed .
I have checked my 8051 Circuit and GSM module with Hyperterminal .
I am trying to print the "received string " on LCD and/or send back to hyperterminal
Can you just look in to it ..
Thanks in Advance..
I am trying to implement your logic for "Reading SMS from SIM900A GSM Module ". But
Could not succeed .
I have checked my 8051 Circuit and GSM module with Hyperterminal .
I am trying to print the "received string " on LCD and/or send back to hyperterminal
Can you just look in to it ..
Thanks in Advance..
#include<REG51.h> #include<string.h> #define dataport P2 sbit rs = P0^3; //Register select pin sbit rw = P0^0; // Fake GND In Hardware sbit en = P0^4; //Enable pin sbit LED1 = P1^0; sbit LED2 = P1^1; sbit LED3 = P0^6; sbit LED4 = P0^7; void rece_isr(); //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,ch; //we can also have a flag for new message bit NewMessage = 0; void DelayMs(unsigned char k) { unsigned int i,j; for(i=0;i<=k;i++) { for(j=0;j<=150;j++) ; } } void delay(unsigned int msec) // Function to provide time delay in msec. { int i,j ; for(i=0;i<msec;i++) for(j=0;j<200;j++); } ////////////////////////////////////LCD STARTS////////////////////////////////////// void lcdcmd(unsigned char item) //Function to send command to LCD { dataport = item; rs= 0; rw=0; en=1; delay(1); en=0; delay(1); } void lcddata(unsigned char item) //Function to send data to LCD { dataport = item; rs= 1; rw=0; en=1; delay(1); en=0; delay(1); } int lcd_string(unsigned char *item) // function to send string to LCD { int x; for(x=0;item[x]!=0;x++) lcddata(item[x]); return(1); } void init_lcd() { lcdcmd(0x38); delay(1); lcdcmd(0x0C); delay(1); lcdcmd(0x01); delay(1); lcdcmd(0x80); delay(1); } ////////////////////////////////////LCD ENDS////////////////////////////////////// ////////////////////////////////Serial Program Starts///////////////////////////// void SerialInit() { EA=0; TH1 = 0xFD; SCON = 0x50; TR1 = 1; RI=0; TI=0; ES=1; TMOD = 0x26; EA = 1; }// End of SerialInit void string_to_pc(unsigned char *temp) { while(*temp) { SBUF= *temp; DelayMs(100); temp++ ; } } void ISR_sc(void) interrupt 4 { //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; string_to_pc('E'); } else { //seems like we have recieved our data //Now stop and indicate that new message has received MyBuff[i] = '\0'; NewMessage = 1; string_to_pc('F'); //do not forget to reset i :) i = 0; // no more errors.. } } else { //there is a miss match //reset counter i = 0; } } void rec_unread_sms() { string_to_pc("AT+CMGR=1"); delay(500); SBUF=0x0D; delay(500); } void delete_sms() { delay(1500); string_to_pc("AT+CMGD=1"); delay(1500); SBUF=0x0D; delay(1500); } /////////////////////////////////////////////////// void main() { SerialInit(); init_lcd(); /* Function for Initlization LCD 16 x 2 */ lcdcmd(0x80); lcd_string("GSM GATEWAY FOR") ; lcdcmd(0xC0) ; lcd_string("INDS. MONITORING") ; lcdcmd(0x01); Test_LEDs(); while(!NewMessage); NewMessage = 0; lcdcmd(0xC0) ; lcd_string(MyBuff) ; string_to_pc(MyBuff); while(1); }
Powered by e107 Forum System