GSM trouble
Fri Dec 28 2012, 07:27 am
I've been reading the topic made by kirangowle "Embedded GSM Development" and try to test it using my GSM sim900D module. I downloaded the post of majoka, title as "(new msg) and connect my gsm to my laptop. When I send a message to my gsm, I dont get any response from the proteus. Need your help please.
btw I already test my gsm modem through HyperTerminal in my laptop(Windows Xp) and its working fine, so far I dont get any problem using it.
thanks.
btw I already test my gsm modem through HyperTerminal in my laptop(Windows Xp) and its working fine, so far I dont get any problem using it.
thanks.
Fri Dec 28 2012, 11:04 pm
@ jepoy12
if modem is working proper with hyper terminal and sending response to pc
then in Proteus it should be work
if you are using usb to serial converter what is comport no
in Proteus assign that no to compim model
then simply call on modem then u should see RING in Proteus
if you feel problem then post here
if modem is working proper with hyper terminal and sending response to pc
then in Proteus it should be work
if you are using usb to serial converter what is comport no
in Proteus assign that no to compim model
then simply call on modem then u should see RING in Proteus
if you feel problem then post here
Sat Dec 29 2012, 12:25 pm
Ok I solve the problem about connecting my modem to laptop and here is the result after I send a message to it.
I used the code you gave to kirangowle at this thread http://www.8051projects.net/t41321/embedded-gsm-development/gsm-modem-8051.htm
and the result when I send the message. It didnt display on the lcd.
I used the code you gave to kirangowle at this thread http://www.8051projects.net/t41321/embedded-gsm-development/gsm-modem-8051.htm
#include<reg51.h> #define buffer 110 sfr port=0xB0; sbit rs = P2^2; sbit rw = P2^1; sbit e = P2^0; sbit D7 = P0^7; sbit LED = P2^3; void delay(unsigned int i); void lcdcmd(unsigned char val); void lcddata(unsigned char val); void lcdinit(); void checkbusy(); void lcd_str (unsigned char *); void tx0(unsigned char); void SMSString(char*text) ; void init(); void clear(void); void read_text(unsigned char * , unsigned char * , unsigned char *); void read_notification(); void clear_mybuff(); unsigned char abc; unsigned char idata msg1[buffer]; unsigned char rec_no[10]; unsigned char time_date[20]; unsigned char code Response[] = "+CMTI"; unsigned char MyBuff[20], k = 0; bit NewMessage = 0; void lcdstr (unsigned char *str) { while(*str){ lcddata(*str++); } } void lcdcmd(unsigned char val) { checkbusy(); P0=val; rs=0; rw=0; e=1; delay(1); e=0; } void delay(unsigned int i) { unsigned int k, l; for(k=0;k<i;k++) for(l=0;l<1000;l++); } void lcddata(unsigned char val) { checkbusy(); P0=val; rs=1; rw=0; e=1; delay(1); e=0; } void lcdinit() { lcdcmd(0x38); // 2 lines 5x7 matrix. delay(5); lcdcmd(0x0c); // Display ON Cursor Blinking. delay(5); lcdcmd(0x01); // Clear Display Screen. delay(5); lcdcmd(0x06); // Increment Cursor. delay(5); } void checkbusy() { D7=1; rs=0; rw=1; while(D7!=0) { e=0; delay(1); e=1; } } void main () { clear(); lcdinit(); lcdcmd(0xd4); lcddata('K'); delay(10); 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 while(1) { IE=0x90; k=0; lcdcmd(0xd4); lcddata('R'); delay(100); while(!NewMessage); IE=0x00; lcdcmd(0xd4); lcddata('I'); delay(10); NewMessage = 0; read_notification(); delay(100); read_text(msg1,rec_no,time_date); clear(); clear_mybuff(); } } void read_notification() { lcdcmd(0x01); lcdcmd(0xd4); lcddata('Z'); delay(50); clear(); SMSString("AT+CMGR="); tx0(MyBuff[12]); SMSString("\r"); IE=0x90; } void init() { abc=0; TL1=0XFD; //9600 @ 11.0592 TH1=0xFD; TMOD=0x20; SCON=0x50; TR1=1; } void SMSString(unsigned char* text) //function to send SMS using GSM modem { while (*text) { tx0(*text++); } } void tx0(unsigned char x) //send data to modem { SBUF=x; while(TI==0); TI=0; } void serial () interrupt 4 { unsigned char ch; if(RI){ ch = SBUF; //character is read if((ch == Response[k]) || (k > 4)) { if(ch != 0x0D) // 0x0D means data received.. { MyBuff[k++] = ch; } else { MyBuff[k] = '\0'; NewMessage = 1; k = 0; } } else { msg1[abc]=ch; //received msg is stored. abc++; k = 0; } } if(TI) TI = 0; RI = 0; //clear flag } void clear_mybuff() { unsigned int a; for(a=0;a<25;a++) MyBuff[a]=0x00; } void clear(void) { unsigned int a; for(a=0;a<buffer;a++) msg1[a]=0x00; } void read_text( unsigned char *msg,unsigned char *no ,unsigned char *time) { // it will decode thistype of message only // +CMGL: 7,"REC UNREAD" , "+919242445514","Kiran","10/12/09,18:03:50+22" // hellow world... // first + will not store in msg1 array it will be in MyBuff as i think unsigned char *temp; temp=msg; do msg++; while(*msg!='+'); // reaching at no do *no++=*msg++; while(*msg!='"'); *no++='\0'; msg++; msg++; msg++; do msg++; while(*msg!=','); // reaching at time msg++; msg++; do *time++=*msg++; while(*msg!='+'); // raching at message *time='\0'; do msg++; while(*msg!='\n'); msg++; do *temp++=*msg++; while(*msg!='\r'); // reaching at end of message *temp='\0'; lcdcmd(0x80); // ist line address lcdstr(rec_no); // array having receipt no lcdcmd(0xC0); // 2nd line address lcdstr(time_date); // array having date and time lcdcmd(0x94); // 3rd line address lcdstr(msg1); // array having message }
and the result when I send the message. It didnt display on the lcd.
Thu Jan 03 2013, 01:37 pm
@ jepoy12
the results are not as it should be
do these changes
use the delay_ms instead of delay
may be it is short that is why u can't see a message
from lcd point of view its look like that it is not able to detect new sms
from hyper terminal point of view its look like it is reading sms
some thing is going wrong
the results are not as it should be
do these changes
use the delay_ms instead of delay
may be it is short that is why u can't see a message
void delay_ms (unsigned int count) { unsigned int i; while(count) { i = 115; while(i> 0) i--; count--; } } void read_notification() { lcdcmd(0x01); lcdcmd(0xd4); lcddata('Z'); delay(50); clear(); SMSString("AT+CMGR="); tx0(MyBuff[12]); if(MyBuff[13]!=0) tx0(MyBuff[13]); tx0('\r'); abc=0; IE=0x90; } // use big delay here read_notification(); delay_ms(2000); read_text(msg1,rec_no,time_date); clear(); clear_mybuff();
from lcd point of view its look like that it is not able to detect new sms
from hyper terminal point of view its look like it is reading sms
some thing is going wrong
[ Edited Thu Jan 03 2013, 01:39 pm ]
Thu Jan 03 2013, 05:45 pm
hi majoka,
things are really tough last year, I broke my GSM and some stuffs for my project. Earlier I just received my shipments of new GSM and my project items.
Here's the new code I'm using.
things are really tough last year, I broke my GSM and some stuffs for my project. Earlier I just received my shipments of new GSM and my project items.
Here's the new code I'm using.
#include <REGX52.H> #define LCD P1 #define LCD_EN 0x80 #define LCD_RS 0x20 //LCD Commands #define LCD_SETMODE 0x04 #define LCD_SETVISIBLE 0x08 #define LCD_SETFUNCTION 0x28 #define LCD_SETDDADDR 0x80 void delayms(unsigned char); void delayus(unsigned char); void lcd_init(); void lcd_reset(); void lcd_4line(); void lcd_cmd (char); void lcd_data(unsigned char); void lcd_str (unsigned char *); void clear(void); void tx0(unsigned char); void delay_sms (unsigned int); void SMSString(char*text) ; void init(); void read_text(unsigned char * , unsigned char * , unsigned char *); void gsm_loop(unsigned int); unsigned char j,abc; unsigned char idata msg1[150]; unsigned char rec_no[20]; unsigned char time_date[20]; unsigned int var,i,n,x; void serial () interrupt 4 { msg1[abc]=SBUF; abc++; RI=0; } void main (void) { n=0x35; gsm_loop(n); delay_sms(1000); } void gsm_loop(unsigned int n) { for(i=0x31;i<=n;i++) { clear(); init(); lcd_init(); var=i; 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,1,0,0,0\r"); // notification of new sms delay_sms(1000); SMSString( "AT+CMGR="); // AT command to read sms tx0(var); SMSString("\r"); IE=0X90; // Enable serial interrupt delay_sms(2000); read_text(msg1,rec_no,time_date); // read sms and store in buffer msg1 clear(); delay_sms(2000); IE=0X00; // Disable all interrupt } } void init(void) { j=0; abc=0; TL1=0XFD; //9600 @ 11.0592 TH1=0xFD; TMOD=0x20; SCON=0x50; TR1=1; } 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==0); TI=0; EA=1; } void delay_sms (unsigned int count) { unsigned int i; // Keil v7.5a while(count) { i = 115; while(i> 0) i--; count--; } } void read_text( unsigned char *msg,unsigned char *no ,unsigned char *time) { unsigned char *temp; temp=msg; do msg++; while(*msg!='+'); do msg++; while(*msg!='+'); // reaching at no do *no++=*msg++; while(*msg!='"'); // reaching at time *no++='\0'; msg++; msg++; msg++; do *time++=*msg++; while(*msg!='+'); // raching at message *time='\0'; do msg++; while(*msg!='\n'); msg++; do *temp++=*msg++; while(*msg!='\r'); // reaching at end of message *temp='\0'; lcd_cmd(0x80); // ist line address lcd_str(rec_no); // array having receipt no lcd_cmd(0xC0); // 2nd line address lcd_str(time_date); // array having date and time lcd_cmd(0x94); // 3rd line address lcd_str(msg1); // array having message } void lcd_reset() { LCD = 0xFF; delay_sms(40); LCD = 0x03+LCD_EN; LCD = 0x03; delay_sms(40); LCD = 0x03+LCD_EN; LCD = 0x03; delay_sms(5); LCD = 0x03+LCD_EN; LCD = 0x03; delay_sms(5); LCD = 0x02+LCD_EN; LCD = 0x02; delay_sms(5); } void lcd_init () { lcd_reset(); lcd_cmd(LCD_SETFUNCTION); // 4-bit mode - 1 line - 5x7 font. lcd_cmd(LCD_SETVISIBLE+0x04); // Display no cursor - no blink. lcd_cmd(LCD_SETMODE+0x02); // Automatic Increment - No Display shift. lcd_cmd(LCD_SETDDADDR); // Address DDRAM with 0 offset 80h. } void lcd_cmd (char cmd) { LCD = ((cmd > > 4) & 0x0F)|LCD_EN; LCD = ((cmd > > 4) & 0x0F); LCD = (cmd & 0x0F)|LCD_EN; LCD = (cmd & 0x0F); delay_sms(1); } void lcd_data (unsigned char dat) { LCD = (((dat > > 4) & 0x0F)|LCD_EN|LCD_RS); LCD = (((dat > > 4) & 0x0F)|LCD_RS); LCD = ((dat & 0x0F)|LCD_EN|LCD_RS); LCD = ((dat & 0x0F)|LCD_RS); delay_sms(1); } void clear(void) { unsigned char a; for(a=0;a<100;a++) msg1[a]=0x00; } void lcd_str (unsigned char *str) { while(*str){ lcd_data(*str++); } }
[ Edited Sat Jan 05 2013, 05:31 pm ]
Fri Jan 04 2013, 09:09 am
Got question.
If I want it to keep on looping even if there is no message is that possible?
Edit:
I found the solution.
I delete the For looping and now its looping to AT+CMGR=1 as I wanted it to be, but this new problem again occurs, when there is no message sent on the GSM, the LCD display the word "OK".
Can someone help me how to make it display nothing?
Thanks.
If I want it to keep on looping even if there is no message is that possible?
Edit:
I found the solution.
I delete the For looping and now its looping to AT+CMGR=1 as I wanted it to be, but this new problem again occurs, when there is no message sent on the GSM, the LCD display the word "OK".
Can someone help me how to make it display nothing?
Thanks.
[ Edited Sat Jan 05 2013, 09:37 am ]
Sat Jan 05 2013, 11:26 am
You can try some thing like this.
unsigned char code Response[] = "OK"; unsigned char code Response1[] = "+CMGR"; void check_OK() { IE=0x90; while(!OK); { OK=0; k=0; } return; } //main OK=0; while(1) { k=0; SMSString("AT+CMGR=1\r"); check_OK(); if(NewMessage) { // Display on LCD NewMessage=0; Delete the Msg from 1st loc. SMSString("AT+CMGD=1\r"); } } // serial Interrupt routine void serial () interrupt 4 { unsigned char ch; if(RI){ ch = SBUF; //character is read RI = 0; //clear flag if(ch == Response[k] || (k > 1) ) // check for OK response { if(ch != 0x0D) // 0x0D means data received.. { OK=1; k++; } } if(ch == Response1[abc] || (abc > 4) ) // check for CMGR response { if(ch!=0x0D) { msg1[abc++]=ch; // store the entire msg } else { if(ch==0x0D && count==0) { count++; } else { msg1[abc++]='\r'; msg1[abc]='\0'; OK=1; abc=0; NewMessage=1; // this tells new msg has been arrived and stored in msg[]; } } } } }
Sat Jan 05 2013, 07:03 pm
Thanks kirangowle but is the code you posted is for the new code Im using or the first code I've posted above?
Mon Jan 07 2013, 08:53 pm
The above code is solution for your below question.
You can modify your ISR and main() in first code accordingly.
let me know if you still faces same error.
Got question.
If I want it to keep on looping even if there is no message is that possible?jepoy12
You can modify your ISR and main() in first code accordingly.
let me know if you still faces same error.
Tue Jan 08 2013, 05:33 pm
Im planning to change the LCD to dot matrix would that be possible? So far the codes are working properly but instead of LCD I want to use a dot matrix.
Powered by e107 Forum System