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.

Gsm interfacing to micro controller.

Status
Not open for further replies.

Rohi231

Member level 2
Joined
Mar 21, 2012
Messages
53
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,673
Hello everyone.
Currently i am working on a gsm home automation system. I have sent and received messages through hyper terminal while connecting to gsm. But when i connected gsm to microcontroller (P89v51rd2) its not working. I have checked by connecting micro controller to pc. Its working fine. Have connected
2 nd pin(gsm modem) of db 9 connector to 3 rd pin of (micro controller) db 9 connector.
3 rd pin(gsm modem) of db 9 connector to 2 nd pin of (micro controller) db 9 connector.
5 th pin(gsm modem) of db 9 connector to 5 th pin of (micro controller) db 9 connector.

My program:

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include<P89V51RX2.h> // include at89x51 . h
#include<stdio.h>// include stdio . h
#include<stdlib.h>// include stdlib . h
 
unsigned char Command_AT[]=" AT\r\n";
 
 
 
 
unsigned char Command_save[]="AT&W\r\n";  //save settings//
 
unsigned char Command_CMGF[]="AT+CMGF=1\r\n";
// AT+CMGF for selecting Text Mode
 
                  
unsigned char Command_CMGS[]="AT+CMGS =\"919743338587\"\r\n";
// recepient mobile number
 
 
unsigned char msg02[]="Hello!";
 
 
void initialize_serialcommunication(void)
{
                   SCON  = 0x50;
                   TMOD  = 0x20;
                           TH1   =-3;
                   TL1   = 0xFD;
                              TR1   = 1;
                           TI    = 1;
                  
}
 
void delay2(void)
{
    unsigned int i;
    for(i=0;i<65000;i++);
}
 
void gsmcmdsend(unsigned char *cmd)
{ 
    
    while(*cmd!='\0')
    {
     SBUF=*cmd;
     while(TI==0);
     TI=0;
     cmd++;
    } 
     
}
 
 
void gsminit(void)
{ // AT COMMANDS
    delay2();
    delay2();
    delay2();
    delay2();
    delay2();
    delay2();
    delay2();
    gsmcmdsend(Command_AT);
    delay2();
    
    gsmcmdsend(Command_save);
    delay2();
    gsmcmdsend(Command_CMGF);
    delay2();
    gsmcmdsend(Command_CMGS);
    delay2();
    gsmcmdsend(msg02);
    delay2();
    SBUF = 0x1A;
    while(TI==0); TI = 0;
     
 
}
 
 
 
void main (void)
{
    initialize_serialcommunication();
    gsminit();
    while (1);
}




Help me out:roll:
 
Last edited by a moderator:

SBUF = 0x1A;
hit send '/r' after..

ya. Thanks. I am not able to program for receiving gsm to micro controller. For example it will send "OK". How to compare this "OK".
For this i can write
unsigned char code str1[3]="OK";
Sir, plz. can i know how to compare this with SBUF. I am able to compare only single byte.
THAnk you.
 

its quiet simple...first you have to use you IC in interrupt service routine if you want to receive message...But if no concern in receiving message then it will be OK.

TO check ok you should write your code like this:

Code:
	while(serial_read()!='O');
        while(serial_read()!='K');
after sending a command to the GSM module..Put this thing just after that..if your condition would comes false it will come down

---------- Post added at 19:53 ---------- Previous post was at 19:48 ----------

if you want to compare a string then store data in string..then compare it
like

Code C - [expand]
1
2
3
4
5
6
7
8
9
for(i=0; SBUF!=\r; i++)
{
     str1[i]=serial_read();
}
then check
if(str1[]=='OK')
{
then do what you want.
}

 
Last edited by a moderator:
Rohi231 said:
How to compare this "OK".
After you read the serial bytes (in let's say str[] array), you can compare it like:

Code:
if (str[0] == '0')
{
  if (str[1] == 'K')
  {
    //put the desired code in here
  }
}



raowakeel said:
TO check ok you should write your code like this:

while(serial_read()!='O');
while(serial_read()!='K');
And what will happen if something like an "ONDFSK" is received? This is not "OK", but code flow will be allowed to move forward.


raowakeel said:
for(i=0; SBUF!=\r; i++)
{
str1=serial_read();
}

if(str1[]=='OK')
{

}

What is this? Can this be compiled without errors? In which compiler?
 
Last edited:
Thanks raowakeel. Let me check this .

---------- Post added at 09:13 ---------- Previous post was at 09:13 ----------

I will check this too. Thanks.
 

i think the best method to read a message using interrupt...this will give you good experience.
 

i am not sure that GSM phone and Module work in a same way..if yes then surely i can help you.
 

ok dear..then ask what you want to be helpful for you??
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top