Monday, 23 December 2013

GSM

IN THIS POST I WOULD LIKES TO TEACH ABOUT GSM INTERFACING WITH CODING...


GSM/GPRS MODEM is a class of wireless MODEM devices that are designed for communication of a computer with the GSM and GPRS network. It requires a SIM (Subscriber Identity Module) card just like mobile phones to activate communication with the network. Also they have IMEI (International Mobile Equipment Identity) number similar to mobile phones for their identification. A GSM/GPRS MODEM can perform the following operations: 

1.      Receive, send or delete SMS messages in a SIM.

2.      Read, add, search phonebook entries of the SIM.

3.      Make, Receive, or reject a voice call. 


The MODEM needs AT commands, for interacting with processor or controller, which are communicated through serial communication. These commands are sent by the controller/processor. The MODEM sends back a result after it receives a command. Different AT commands supported by the MODEM can be sent by the processor/controller/computer to interact with the GSM and GPRS cellular network.

AT COMMANDS: 

AT commands are used to control MODEMs. AT is the abbreviation for Attention. These commands come from Hayes commands that were used by the Hayes smart modems. The Hayes commands started with AT to indicate the attention from the MODEM. The dial up and wireless MODEMs (devices that involve machine to machine communication) need AT commands to interact with a computer. These include the Hayes command set as a subset, along with other extended AT commands.

AT commands with a GSM/GPRS MODEM or mobile phone can be used to access following information and services:

1.      Information and configuration pertaining to mobile device or MODEM and SIM card.

2.      SMS services.

3.      MMS services.

4.      Fax services.

5.      Data and Voice link over mobile network.

The Hayes subset commands are called the basic commands and the commands specific to a GSM network are called extended AT commands.

Explanation of commonly used AT commands:
        
1) AT - This command is used to check communication between the module and the computer.

For example,

AT

OK

The command returns a result code OK if the computer (serial port) and module are connected properly. If any of module or SIM is not working, it would return a result code ERROR.

2) +CMGF - This command is used to set the SMS mode. Either text or PDU mode can be selected by assigning 1 or 0 in the command.

SYNTAX: AT+CMGF=<mode>

0: for PDU mode

1: for text mode

The text mode of SMS is easier to operate but it allows limited features of SMS. The PDU (protocol data unit) allows more access to SMS services but the operator requires bit level knowledge of TPDUs. The headers and body of SMS are accessed in hex format in PDU mode so it allows availing more features.

For example,

AT+CMGF=1

OK
    
1) +CMGW - This command is used to store message in the SIM.

SYNTAX: AT+CMGW=” Phone number”> Message to be stored Ctrl+z

As one types AT+CMGW and phone number, ‘>’ sign appears on next line where one can type the message. Multiple line messages can be typed in this case. This is why the message is terminated by providing a ‘Ctrl+z’ combination. As Ctrl+z are pressed, the following information response is displayed on the screen.

+CMGW: Number on which message has been stored.

4) +CMGS - This command is used to send a SMS message to a phone number.

SYNTAX: AT+CMGS= serial number of message to be send.

As the command AT+CMGS and serial number of message are entered, SMS is sent to the particular SIM.

For example,

AT+CMGS=1

OK 
5) ATD - This command is used to dial or call a number.

SYNTAX: ATD<Phone number>(Enter)

For example,

ATD123456789

6) ATA - This command is used to answer a call. An incoming call is indicated by a message ‘RING’ which is repeated for every ring of the call. When the call ends ‘NO CARRIER’ is displayed on the screen.

SYNTAX: ATA (Enter)

As ATA followed by enter key is pressed, incoming call is answered.

For example,

RING

RING

ATA

7) ATH - This command is used to disconnect remote user link with the GSM module.

SYNTAX: ATH (Enter)

8051 PROGRAM TO INTERFACE GSM

#include<reg51.h>
#include"gsm2012.h"
#include"uart2012.h"
#include"DELAY2012.h"
/********************************************************************/
void GSM_INIT(void)
{
            unsigned char i=0;
            unsigned char code *GSM_CMD[7]={"AT","ATE0","AT+CPIN=?","AT+CMGF=1",                                                                                                            "AT+CNMI=2,2,0,0,0","AT&W","AT+CMGD=1"};
           
            GSM_CMD_SEND(GSM_CMD[0]);GSM_CMD_SEND(GSM_CMD[1]);GSM_CMD_SEND(GSM_CMD[2]);
            GSM_CMD_SEND(GSM_CMD[3]);GSM_CMD_SEND(GSM_CMD[4]);GSM_CMD_SEND(GSM_CMD[5]);            
}
/********************************************************************/
void GSM_CMD_SEND(unsigned char *CMDWRT)
{
            unsigned char i;
            for(i=0;*CMDWRT!='\0';i++)
            {          
                        SBUF=*CMDWRT;
                        while(TI==0);
                        TI=0;
                        CMDWRT++;
            }
            delay(5);
            ENTER();
            while(RX_DATA()!='O');
            while(RX_DATA()!='K');
            delay(30);
}
/*********************************************************************************************/
void ENTER(void)
{
            SBUF=0x0A;//line feed
            while(TI==0);
            TI=0;
            SBUF=0x0D;//carriage return
            while(TI==0);
            TI=0;
}
/***************************** END *************************************/
void GSM_MSG_SEND(unsigned char *CMDWRT ,unsigned char *MSG)
{
            unsigned char i;
    TX_STRING("AT+CMGS=");
            TX_DATA('\"');TX_DATA('+');
            for(i=0;i<12;i++)
            {          
                        SBUF=*CMDWRT;
                        while(TI==0);
                        TI=0;
                        CMDWRT++;
            }
            TX_DATA('\"');
            ENTER();
            TX_STRING(MSG);
            TX_DATA(0x1A);
            delay(30);
}
/***************************** END *************************************/


/********************************************************************************/
// Main Program for GSM………………………………………………
#include"UART2012.h"
#include"LCD2012.h"
#include"GSM2012.h"
#include"delay2012.h"
void RX_MSG();
#include <REG51.H>
unsigned char msg[15],PH_NUM[12];
void RX_MSG()
{
            unsigned i=0,j=0;
                        while((RX_DATA())!='+');
                        while((RX_DATA())!=':');
                        while((RX_DATA())!='\"');while((RX_DATA())!='+');
                        for(i=0;i<12;i++)
                        {
                                    PH_NUM[i]=RX_DATA(); 
                        }
                        PH_NUM[i] = '\0';                                           
            while(RX_DATA()!='\n');
            for(i=0;i<15;i++)
                        {
                                    msg[i]=RX_DATA();
                        if(msg[i]=='\r')
                                    break;
                        } 
                        P0= 0xFF;
            msg[i]='\0';
                                   
                GSM_MSG_SEND("9999999999","Hello");
}

void main()
{
 P0 = 0x00 ;
// LCD_INIT();
delay(10);
 //LCD_DATA_WR1("LCD INIT DONE");
 UART_INIT();
delay(10);
 GSM_INIT();
delay(10);
 // LCD_DATA_WR1("GSM INIT DONE");

while(1)
 {
   RX_MSG();
 //  LCD_DATA_WR1("MSgRXed");
 }


SIM 300 is the famous GSM modem for the project development . We can use this GSM modem as a mobile phone itself for sending and receiving messages and also make a call and receive a call. By interfacing the GSM modem with the microcontroller we need to add UART that is serial communication in our code. By using the GSM modem with the microcontroller we can communicate the other devices also.



 

No comments:

Post a Comment

share your thoughts