GSM MODEM with 8051
Fri Dec 03 2010, 07:18 pm
hi kiran
there is no need of this
do it as
there is no need of this
unsigned char ch;
while(RI==0);
ch=SBUF;
do it as
unsigned char ch;
ch=SBUF;
Sat Dec 04 2010, 11:16 pm
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 expertsmajoka
Thank you majoka i am totally flattered
I am glad you're here too
@kiran..
//as you are using interrupts so its better //you keep a flag for tx, and instead of polling // TI, poll that flag bit TI_flag = 0; //usage SBUF = Data_to_send; while(!TI_flag); TI_flag = 0; //Now the ISR.. this what i was expecting... void serial () interrupt 4 { unsigned char ch; if(RI){ ch = SBUF; //character is read RI = 0; //clear flag 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; } } if(TI){ //if its a tx interrupt //clear TI TI = 0; //set a flag to indicate tx has completed TI_flag = 1; } }
In this, why we have to check for carriage return(0x0D).
kirangowle
you response will come in this format
\r\n+CMTI: "SM",1\r\n
we are reading form '+' so we will read till we get a \r or 0x0D got it?
kirangowle like this.
Tue Dec 07 2010, 11:42 am
Sorry guys for delay. i was not well.
@ Ajay,
From your code index no. gets stored in MyBuff[] array.Where shall i store the reserved msg info.
I think in ISR another function should be added to reserve the msg details.
Am i correct guys.
@ Ajay,
From your code index no. gets stored in MyBuff[] array.Where shall i store the reserved msg info.
I think in ISR another function should be added to reserve the msg details.
Am i correct guys.
Tue Dec 07 2010, 01:57 pm
As ISR function is growing, what happens if serial interrupt occurs in ISR itself.
Does it detects or data would be lost.
Does it detects or data would be lost.
Wed Dec 08 2010, 12:25 am
hi kirangowle
if one interrupt is in process and other comes and comes then may be controller hang
generate a flag for indication as when u receive the new message indication after that make this flag high it mean now the data come is data not any indication and do index again to zero then read sms store it in buffer and then decode it
As ISR function is growing, what happens if serial interrupt occurs in ISR itself.
Does it detects or data would be lost.
if one interrupt is in process and other comes and comes then may be controller hang
generate a flag for indication as when u receive the new message indication after that make this flag high it mean now the data come is data not any indication and do index again to zero then read sms store it in buffer and then decode it
Wed Dec 08 2010, 12:58 am
As ISR function is growing, what happens if serial interrupt occurs in ISR itself.
Does it detects or data would be lost.
ISR is not that bit as it looks coz you are reading 1 byte and storing it when you get a match and you will directly be discarding everything in ideal case.
if you look at ISR carefully, we are check RI and then immediately moving data from SBUF to local buffer and then clearing RI flag, incase a new data comes in between (though chances are very less) then RI will be set again and SBUF will have new data. as soon as you come out of ISR, controller will be interrupted again. so there are minimum chances that data will be lost.
Thu Dec 09 2010, 11:05 am
Hi
I have modified main() and read notification() Is this correct.
I have modified main() and read notification() Is this correct.
void main () { clear(); lcdinit(); 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 IE=0x90; delay(10); while(!NewMessage); { NewMessage = 0; read_notification(); IE=0x90; } //New msg indication. // +CMTI: "SM",3 } void read_notification() { IE=0x00; clear(); SMSString("AT+CMGR="); tx0(MyBuff[12]); SMSString("\r"); IE=0x90; delay(100); read_text(msg1,rec_no,time_date); clear(); void SMSString(unsigned char* text) //function to send SMS using GSM modem { while (*text) { tx0(*text++); } } void tx0(unsigned char x) //send data to serial port 0 { EA=0; SBUF=x; while(!TI_flag); TI_flag = 0; EA=1; } void serial () interrupt 4 { unsigned char ch; if(RI){ ch = SBUF; //character is read RI = 0; //clear flag if((ch == Response[k]) || (k > 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.. { 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; k = 0; } } else { msg1[abc]=ch;//received msg is stored. abc++; k = 0; } } if(TI) { //if its a tx interrupt //clear TI TI = 0; //set a flag to indicate tx has completed TI_flag = 1; } } }
Thu Dec 09 2010, 01:08 pm
hi kirangowle
its looking fine
try it on hardware u will get better answer there
its looking fine
try it on hardware u will get better answer there
Thu Dec 09 2010, 03:22 pm
Hi,
No output.
Its not getting into the main while loop itself.
I have tested as above, when new msg received it should enter into the while loop and should display 'I' on LCD..
But its not displaying.
ISR is as below.
No output.
Its not getting into the main while loop itself.
SMSString( "AT+CNMI=2,1,0,0,0\r"); // notification of new sms while(1) { IE=0x90; delay(10); while(!NewMessage); { lcdcmd(0xd4); lcddata('I'); delay(100); NewMessage = 0; read_notification(); IE=0x90; } //New msg indication. // +CMTI: "SM",3 }
I have tested as above, when new msg received it should enter into the while loop and should display 'I' on LCD..
But its not displaying.
ISR is as below.
void serial () interrupt 4 { unsigned char ch; if(RI){ ch = SBUF; //character is read RI = 0; //clear flag if((ch == Response[k]) || (k > 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.. { 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; k = 0; } } else { msg1[abc]=ch;//received msg is stored. abc++; k = 0; } } if(TI) { //if its a tx interrupt //clear TI TI = 0; //set a flag to indicate tx has completed TI_flag = 1; } }
Thu Dec 09 2010, 04:43 pm
Hi,
Working!!!
The problem was with
In above code i replaced TI_flag with TI as below.
When first msg is been displayed if i send another msg, it would be hanged.
I think for the next msg arrival we should clear the MyBuff[].
Working!!!
The problem was with
void tx0(unsigned char x) //send data to serial port 0 { EA=0; SBUF=x; while(!TI_flag); TI_flag=0; EA=1; }
In above code i replaced TI_flag with TI as below.
while(TI==0); TI=0;
When first msg is been displayed if i send another msg, it would be hanged.
I think for the next msg arrival we should clear the MyBuff[].
Powered by e107 Forum System