Monday, 23 July 2018

Interface a GSM (SIM 300) Modem with ARM Microcontroller (LPC2148)

Aim:

GSM (Global System for Mobile Communication) technology lets user to communicate with others across mobile networks hence it offers a vast area of coverage. Interfacing GSM technology with microcontroller will enable us to extend the communication to cover large area. This tutorial will teach you about interfacing GSM module with LPC2148 ARM microcontroller and program it to communicate it with another user.
F3FLJRGIDIN6G8Y.MEDIUM

Description:

STEP 1: MODEM TESTING:

The Modem consists of two indicating LED’s Green and Red to indicate the availability of the network. Green indicates the availability of the network whereas red indicates its absence. Turn the modem ON and wait for sometime to register itself in GSM network.

STEP 2: INTERFACING WITH AVR MICROCONTROLLER:

The Communication between AVR and modem takes place through USART protocol. GSM Modem SIM900 works on TTL level hence we can interface directly to RXD and TXD pins of AVR microcontroller. There is no need of using Voltage or level converter between them. However if you ever happen to buy a SIM300 or other module which operates above TTL level, you may want to use MAX232 level converter IC to make the communication possible.

STEP 3: INITIALIZING MODEM:

The modem must be Initialized using the commands and then the process you are about to carry out must be selected. In this tutorial am going to initialize the modem and them make it to send a message “Hi Raghav” to my mobile using the GSM modem.

Block Diagram

gsm

Schematic


Code

// *********************************************************
// Project: Interfacing GSM to LPC2148 microcontroller
// Author: Hack Projects India
// Module description: Operate GSM
// *********************************************************
#include  <lpc214x.h>   //Includes LPC2148 register definitions

 
#define Fosc            12000000     //set clock frequency               
#define Fcclk           (Fosc * 5)                  
#define Fcco            (Fcclk * 4)                 
#define Fpclk           (Fcclk / 4) * 1             

#define  UART_BPS 9600  //Set Baud Rate here

const unsigned char SEND_STRING[] = "I block\r";
const unsigned char SEND_STRING1[] = "UART TRANSMIT\n";


void  Delay_Ticks(unsigned int Delay)  //Function to generate finite delay
{  
   unsigned int i;
   for(; Delay>0; Delay--) 
   for(i=0; i<50000; i++);
}


void  Init_UART0(void)     //This function setups UART0
{  
   unsigned int Baud16;
   U0LCR = 0x83;              // DLAB = 1
   Baud16 = (Fpclk / 16) / UART_BPS;  
   U0DLM = Baud16 / 256;       
   U0DLL = Baud16 % 256;      
   U0LCR = 0x03;
}
    

void  UART0_SendByte(unsigned char data)    //A function to send a byte on UART0
{  
   U0THR = data;        
   while( (U0LSR&0x40)==0 );     
}


void  UART0_SendStr(const unsigned char *str)  //A function to send a string on UART0
{  
   while(1)
   {  
      if( *str == '\0' ) break;
      UART0_SendByte(*str++);     
   }
}
void delay_ms(double ms)
{
 unsigned int i,j;
 for(i=0;i<ms;i++)
   for(j=0;j<255;j++);
}


void gsm_send()
{
  UART0_SendStr("AT");         //attention command
  UART0_SendByte('\r');           //enter
  delay_ms(20);
  UART0_SendStr("AT+CMGF=1");   //change the format of message display
  UART0_SendByte('\r');
  delay_ms(100);
  UART0_SendStr("AT+CMGS=");     //sending message
  UART0_SendByte('"');
  UART0_SendStr("9494156671");    //mobile no
  UART0_SendByte('"');                //
  UART0_SendByte('\r');
  UART0_SendStr("Hack Projects");   //send some string
  UART0_SendByte(0x1a);                // termination from sending

}

int  main(void)
{  
   PINSEL0 = 0x00000005;      // Enable UART0 Rx and Tx pins
   PINSEL1 = 0x00000000;
   PINSEL2 = 0x00000000;

   Init_UART0();
   gsm_send();
   while(1) 
   {  
     
 
   }
   
}       

Downloads:

The code was compiled in Keil uvision4 and simulation was made in Proteus v7.7.
To download code and proteus simulation click here.

Further Reading suggestions:


    No comments:

    Post a Comment