Saturday, September 28, 2013

SIM300 Module

SIM 300:
       When accessing GSM networks comes in picture in embedded system ,one of the best way is to use SIMCOM modules which provides RS-232 interfacing and supports for AT command sets (Commands used for calling,Messaging etc) and usually easy to integrate with embedded modules.In this post i have tried to explain how to Interface the SIM300 module to LPC2148 using UART and send message to a no.

Hardware Connection :
      The SIM module is connected to the LPC2148 by using the UART port.Simple 2 wire connection is made between the board and the module.The Rx and Tx pins are connected accordingly.


CODE:

#include <LPC214X.H>
#include "Serial.h"
#include "Utility.h"
#include "LCD4.h"
int main (void)
{
unsigned char x[200];
int PosAck,y=0;
//hex code of "at enter" command for checking comm status of uart-reply should be ok
 unsigned char AckComm[3]={0x61,0x74,0x0d};
//hex code - for checking balance  -here sim-airtel so,atd*123# 
 unsigned char BalChkComm[9]={0x61 ,0x74 ,0x64 ,0x2A ,0x31 ,0x32 ,0x33 ,0x23,0x0d};
//hex code for selecting text mode-
 unsigned char SmsConfigComm[10]={0x41 ,0x54 ,0x2B ,0x43  ,0x4D ,0x47 ,0x46 ,0x3D ,0x31,0x0d};
// Setting No-9439421905   Bikash
unsigned char SendMsgComm[21]={0x61,0x74,0x2B,0x63,0x6D,0x67,0x73,0x3D,0x22,0x39,0x34 ,0x33 ,0x39 ,0x34 ,0x32 ,0x31 ,0x39,0x30 ,0x35,0x22,0x0D};
 //message body NISt (change it to have diff content )
unsigned char SendMsgBody[5]={0x4E,0x49,0x53,0x54,0x1A};
//lcd data is used temoporarily to store data for lcd display
 unsigned char LcdData[16];
//data used to clear the display
unsigned char LcdClear[16]={0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20};
int i;
LCD4_init (&IOPIN0, 20/*D4*/, 12/*RS*/, 14/*E*/);//initialization of LCD in 4 bit mode
DelayProc(2*CCLOCK);
PINSEL0 = 0;
PINSEL1 = 0;
PINSEL2 &= 0x0000000C;
PINSEL2 |= 0x00000030;
DelayProc(0.2 * CCLOCK);


 UART0_init(9600, 15000, length_8_bit, stop_bit_1, parity_disable, parity_odd);//UART initilization connected to PC
 UART1_init(9600, 15000, length_8_bit, stop_bit_1, parity_disable, parity_odd);//UART initilizaton connected to MODEM

LCD4_sendstr (0,2,"Modem Status :");
      for(i=0;i<3;i++)
                    {
                  UART1_sendchar(AckComm[i]);//Sending At command to check Status
                      }
                      for(i=0;i<7;i++)
                              {
                              x[i]=UART1_getchar();//receiving Status
                              UART0_sendchar(x[i]);
                                }
LcdData[0]=x[5];
LcdData[1]=x[6];

  LCD4_sendstr (1,1,LcdData);
DelayProc(2*CCLOCK);


LCD4_sendstr (1,1,LcdClear);
LCD4_sendstr (0,2,LcdClear);


LCD4_sendstr (0,2,"Account Balance:");
DelayProc(2*CCLOCK);
       for(i=0;i<9;i++)
                    {
                  UART1_sendchar(BalChkComm[i]);//Sending Command to Check balance

                      }
          
                    for(i=0;i<100;i++)
                              {
                              x[i]=UART1_getchar();//getting reply
                              UART0_sendchar(x[i]);
if (x[i]==0x3A && y<2)
{
PosAck=i;
//LCD4_sendstr (1,1,"reached");
y++;
                                    }
                                }

LcdData[0]=x[PosAck];
LcdData[1]=x[PosAck+1];
LcdData[2]=x[PosAck+2];
LcdData[3]=x[PosAck+3];
LcdData[4]=x[PosAck+4];
LcdData[5]=x[PosAck+5];
LCD4_sendstr (1,1,LcdData);


            DelayProc(2*CCLOCK);

                                LCD4_sendstr (1,1,LcdClear);
LCD4_sendstr (0,2,LcdClear);

LCD4_sendstr(0,2,"TEXT mode:");
   DelayProc(2*CCLOCK);
      for(i=0;i<10;i++)
                    {
                  UART1_sendchar(SmsConfigComm[i]);//cONfiguring MODEM in TEXT Mode

                      }
                    for(i=0;i<15;i++)
                              {
                              x[i]=UART1_getchar();
                              UART0_sendchar(x[i]);
if (x[i]==0x31)
{
PosAck=i;
//LCD4_sendstr (1,1,"reached");
//y++;
                                    }
                                }

LCD4_sendstr(1,1,"ok");

DelayProc(2*CCLOCK);
LCD4_sendstr (1,1,LcdClear);
LCD4_sendstr (0,2,LcdClear);



LCD4_sendstr(0,2,"Sending Message");

DelayProc(2*CCLOCK);
for(i=0;i<21;i++)
                    {
                  UART1_sendchar(SendMsgComm[i]);//Adding no to send Message

                      }
                   for(i=0;i<25;i++)
                              {
                              x[i]=UART1_getchar();
                              UART0_sendchar(x[i]);
                                }
     for(i=0;i<5;i++)
                    {
                  UART1_sendchar(SendMsgBody[i]);//Sending Message Body To Receipient. ctrl+z hex code 1A is used at last.

                      }
               for(i=0;i<170;i++)
                              {
                              x[i]=UART1_getchar();
                              UART0_sendchar(x[i]);
                                }

                 LCD4_sendstr(1,1,"ok");
DelayProc(2*CCLOCK);
 LCD4_sendstr (1,1,LcdClear);
LCD4_sendstr (0,2,LcdClear);

}

No comments:

Post a Comment