0% found this document useful (0 votes)
491 views10 pages

Interfacing GSM With LPC2148 For Sending and Receiving Message and Voice Call

This document provides instructions for an laboratory experiment involving interfacing a GSM modem with an LPC2148 microcontroller to send and receive SMS messages and make voice calls. The objectives are to write programs to send an SMS message to a given phone number and to make a voice call. The hardware and software setup is described, along with program listings and steps to compile and run the programs on the hardware. The results are expected to be the SMS message being sent and the status displayed, and a successful or failed voice call indication.

Uploaded by

Bhavin R Darji
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
491 views10 pages

Interfacing GSM With LPC2148 For Sending and Receiving Message and Voice Call

This document provides instructions for an laboratory experiment involving interfacing a GSM modem with an LPC2148 microcontroller to send and receive SMS messages and make voice calls. The objectives are to write programs to send an SMS message to a given phone number and to make a voice call. The hardware and software setup is described, along with program listings and steps to compile and run the programs on the hardware. The results are expected to be the SMS message being sent and the status displayed, and a successful or failed voice call indication.

Uploaded by

Bhavin R Darji
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Laboratory workbook for Advanced Microprocessors (As per Pune University Syllabus)

LAB 3: Interfacing GSM with LPC2148 for sending and receiving message and
voice call

Objective 3.1: Write a program to send message to a particular number.

Part List:
 Educational practice board for ARM7 LPC2148
 All in One General Purpose Board (ASK25)
 +9V Power supply
 USB A to B type cable
 20 pin flat cable
 GSM Modem
 PC
 Eclipse IDE
 Flash Magic Utility

Hardware Connection:
 Connect USB cable between PL3 connector of EPBARM7 and PC.
 Connect 20 Pin flat cable between J1 connector of EPBARM7 board and PL3 connector of
ASK25.
 Insert SIM card in GSM Modem and connect Power supply to GSM modem.
 Connect GSM modem to P8 connector of EPBARM7 board.

Included Files:

HEADER FILES SOURCE FILES


delay.h delay.c
gpio.h gpio.c
gsm.h gsm.c
lcd_lowerlevel.h lcd_lowerlevel.c
lcd_userlib.h lcd_userlib.c
uart.h uart.c
pinsel.h

____________________________________________________________________________
Edutech Learning Solutions Pvt. Ltd. [email protected]
Laboratory workbook for Advanced Microprocessors (As per Pune University Syllabus)

Program Listing:

//message
#include"gsm.h"
#include"lcd_lowerlevel.h"

void main()
{
unsigned char dataBuf[8];
unsigned char *num="09439569077";
unsigned char *message="hi how are u";
unsigned char *c;
int j,i=0;

ConfigUart(Uart0,9600);
InitLcd(Inc,DispShiftOff);

GSM_TMODE(Uart0,dataBuf);
if(dataBuf[12]==0x4F)
{
ClearLcd();
DisplayString("Text Mode",1,1,Off);
DisplayString("Selected",2,1,Off);
DelayMs(1000);
}
else
{
ClearLcd();
DisplayString("Text Mode",1,1,Off);
DisplayString("Not Selected",2,1,Off);
while(1);
}
DisplayString("Mobile number=",1,1,Off);
DisplayString(num,2,1,Off);
GSM_SendSMS(Uart0,num,message);
DelayMs(1000);
ClearLcd();
c="MeSsAgE sEnT";

DisplayString(message,1,1,Off);
DelayMs(2000);
ClearLcd();
for(j=1;j<=12;j++)
{
DisplayCharacter(c[i++],2,j,Off);
DelayMs(100);
}

while(1);

____________________________________________________________________________
Edutech Learning Solutions Pvt. Ltd. [email protected]
Laboratory workbook for Advanced Microprocessors (As per Pune University Syllabus)

Steps to create project and program compilation:


Steps:
 Open Eclipse.exe from “C:\eclipse” folder.
 Now browse to the ARM7 Workspace under E_Workspace (in this case
C:\E_Workspace\ARM7). Click OK to continue.
 Click File > Import…, to import template.
 Click General > Existing Projects into Workspace and click Next.
 First Select Root Directory of your Eclipse Template for ARM7. Then select “Copy
projects into workspace” check box and Click Finish.
 Every time you import a project make sure to rename it. So Right Click Project >
Rename or press F2 while selecting project to rename it.
 Go to File> New > Source File and you will see New Source File Wizard. Enter Source
File name (For example main.c) then Click Finish.
 Write your code and then save your Files.
 Copy necessary .c and .h files to your local project folder. They will be added to your
project in Eclipse IDE

Steps to use hardware:

 Connect 9V DC Power supply to the educational practice board for ARM7


 Connect the board with the USB port of the PC using the USB A to B type cable.
 Using the RUN/PROGRAM mode selection switch, set the board in the program
mode. This will be indicated by the red LED.
 Apply Reset condition by pressing the RESET switch to ensure proper
communication.
 Using download tool (Flash Magic) downloads the .HEX file to the target board.
 Connect the PL3 connector of EPB ARM7 board to PC. Connect 20 pin flat cable
between J1 connector of EPBARM7 board and PL3 connector of ASK25.
 Insert SIM card in GSM Modem and Connect Power supply to it.
 Connect GSM modem to P8 connector of EPBARM7 board.
 Using the RUN/PROGRAM mode selection switch, set the board in the run mode.
This will be indicated by the green LED and apply reset to execute the program.

Result:
It will message a number you entered in program and display status on LCD.

____________________________________________________________________________
Edutech Learning Solutions Pvt. Ltd. [email protected]
Laboratory workbook for Advanced Microprocessors (As per Pune University Syllabus)

Objective 3.2: Write a program to make a call using GSM modem.

Part List:
 Educational practice board for ARM7 LPC2148
 All in One General Purpose Board (ASK25)
 +9V Power supply
 USB A to B type cable
 20 pin flat cable
 GSM Modem
 PC
 Eclipse IDE
 Flash Magic Utility

Hardware Connection:
Connect USB cable between PL3 connector of EPBARM7 and PC. Connect 20 Pin flat
cable between J1 connector of EPBARM7 board and PL3 connector of ASK25.
Connect Power supply to GSM modem and insert SIM card in it.
Connect GSM modem to P8 connector of EPBARM7 board.

Included Files:

HEADER FILES SOURCE FILES


LPC214x.h -

____________________________________________________________________________
Edutech Learning Solutions Pvt. Ltd. [email protected]
Laboratory workbook for Advanced Microprocessors (As per Pune University Syllabus)

Program Listing:

/** This Program is used to make a call using GSM Modem on a specified number.
*/

#include "lpc214x.h"

/* Macro Definitions */
#define SET(x) (1<<x)
#define CLR(X) (0<<X)
#define CRYSTAL_FREQUENCY_IN_HZ 11059200
#define PLL_MULTIPLIER 1

// Macros (as arguments) for the Delay() function


#define DELAY_15MS CRYSTAL_FREQUENCY_IN_HZ*PLL_MULTIPLIER/2304
#define DELAY_6MS CRYSTAL_FREQUENCY_IN_HZ*PLL_MULTIPLIER/5760
#define DELAY_250US CRYSTAL_FREQUENCY_IN_HZ*PLL_MULTIPLIER/138240
#define DELAY_TINY CRYSTAL_FREQUENCY_IN_HZ*PLL_MULTIPLIER/11059200
#define FOSC 12000000

/* Function Declaration for LCD */


void Delay(unsigned loops);
void Toggle_En(void);
void Lcd_Init(void);
void Lcd_Cmd(char lcdcmd);
void Lcd_Data(char lcddata);
void Lcd_String(char *string);

/* Function Declaration for UART0 */


void Uart0_Init(unsigned long BaudRate);
void Uart0_Tx(char Data);
void Uart0_String(char *Data);
char Uart0_Rx(void);

/* Function Declaration for GSM */


void GSM_Test (void);
char GSM_Call(void);
char GSM_Ack (void);

/* Main Program */
int main(void)
{
char status=0;
Lcd_Init();
Uart0_Init(9600); // UART0 initialized with
Baudrate=9600

Lcd_String("GSM Calling...");
status = GSM_Call ();
Lcd_Cmd(0xC0);

if(status)
Lcd_String("Call: Successful");
____________________________________________________________________________
Edutech Learning Solutions Pvt. Ltd. [email protected]
Laboratory workbook for Advanced Microprocessors (As per Pune University Syllabus)

else
Lcd_String("Call: Failed");

while(1);
}

/***************************************************************************
UART0 Functions
******************************************************************************/
/** This Program initialize the UART0 **/
void Uart0_Init(unsigned long BaudRate)
{
unsigned int CountVal;
VPBDIV = 0X01; // to choose pclk=cclk

PINSEL0 &= ~0x0F; // Clearing GPIO Values for Pin0.0 and P0.1 to config it for UART0
PINSEL0 |= 0x05; // Configure P0.0 and P0.1 for UART0 TxD and RxD
IO0DIR &= ~0x02; // Direction: P0.1 RX as input
IO0DIR |= 0x01; // Direction: P0.0 TX as Output

U0FCR = 0X07; // Reset FIFO and Enable it

U0LCR |= 0x03; // databits: 8, parity: No, stopbit: 1

CountVal = FOSC /(16 * BaudRate); // Pg.150 LPC2148 User Manual (Rev. 4.0 2012
Edition)
U0LCR |= (0x01<<7); // Divisor latch enable for setting of Fractoinal
divisor value

U0DLL = (CountVal & 0XFF); // Store DLL


U0DLM = ((CountVal >> 8) & 0XFF); // Store DLM

if(BaudRate >=115200 && BaudRate < 460800 )


{
U0FDR |= (1<<0); // DIVADDVAL = 1
U0FDR |= (12<<4); // MULVAL = 12
}

U0LCR &= ~(0x01<<7);


U0TER |= (1<<7); // UART0 Enable
}

/** This Function is used to transmit data using UART0 **/


void Uart0_Tx(char Data)
{
while(!(U0LSR & 0x20)); // Wait until UART0 FIFO gets empty
U0THR = Data; // Transmit data using Transmit holding register
}

/** This Function is used to transmit string using UART0 **/


void Uart0_String(char *Data)
{
____________________________________________________________________________
Edutech Learning Solutions Pvt. Ltd. [email protected]
Laboratory workbook for Advanced Microprocessors (As per Pune University Syllabus)

while(*Data) // While until string gets complete


Uart0_Tx(*Data++); // UART0 Transmit character function
}

/** This Function is used to Receive data using UART0 **/


char Uart0_Rx(void)
{
char Data;

while(!(U0LSR & 0x01)); // Wait for Single character in Receive FIFO


Data = U0RBR; // Receive character from Receive holding register to local
variable
return(Data); // Return Received character
}

/***************************************************************************
GSM Functions
******************************************************************************/

void GSM_Test (void)


{
char Data,sbuf[2];
int i=0,Read_Status=0;

Uart0_String("AT\r"); // Send Connection Test command AT\r


while(i<160) // Receive Timeout
{
i++;
Data = Uart0_Rx(); // Receive Character from GSM
sbuf[0]=sbuf[1]; // Store character1 in character0
sbuf[1]=Data; // Store Received character from GSM to character1
if((sbuf[0]=='O')&&(sbuf[1]=='K')) // check if character0 = 'O' and character1 = 'K'
{
Read_Status=1; // If True Set Read_Status
break;
}
}
if(Read_Status)
{
Lcd_Cmd(0xC0);
Lcd_String("GSM Test = OK");
}
else
{
Lcd_Cmd(0xC0);
Lcd_String("GSM Test = FAIL");
}
}

char GSM_Call(void)
{
Uart0_String("ATD09427304539;\r");

____________________________________________________________________________
Edutech Learning Solutions Pvt. Ltd. [email protected]
Laboratory workbook for Advanced Microprocessors (As per Pune University Syllabus)

if(GSM_Ack())
return(1);
else
return(0);
}

char GSM_Ack (void)


{
char Data,sbuf[2];
int i=0,Read_Status=0;

while(i<160) // Receive Timeout


{
i++;
Data = Uart0_Rx(); // Receive Character from GSM
sbuf[0]=sbuf[1]; // Store character1 in character0
sbuf[1]=Data; // Store Received character from GSM to character1
if((sbuf[0]=='O')&&(sbuf[1]=='K')) // check if character0 = 'O' and character1 = 'K'
{
Read_Status=1; // If True Set Read_Status
break;
}
}
return (Read_Status);
}

/***************************************************************************
LCD Functions
******************************************************************************/

/*** This is Delay Function ***/


void Delay(unsigned loops)
{
unsigned i;
for (i=0; i<loops; i++) {}
}

/*** This function is used to Toggle Enable pin for LCD. ***/
void Toggle_En(void)
{
Delay(DELAY_250US); // Delay larger for 8bit mode
IO0SET = 0X00000080; // Enable pin = 1;
Delay(DELAY_250US); // Delay larger for 8bit mode
IO0CLR = 0X00000080; // Enable pin = 0;
}

/*** This function is used to pass command to LCD. ***/


void Lcd_Cmd(char lcdcmd)
{
IO0CLR = 0x00000020; // Clear RS Pin ; It will work as command
IO0SET = lcdcmd << 8; // clear data line
IO0CLR = ~lcdcmd << 8; // Data should be shifted to 8th pin
____________________________________________________________________________
Edutech Learning Solutions Pvt. Ltd. [email protected]
Laboratory workbook for Advanced Microprocessors (As per Pune University Syllabus)

Delay(DELAY_TINY);
Toggle_En(); // Toggle Enable pin to latch command
Delay(DELAY_250US); // Delay : To stabilize the command
}

/*** This function is used to pass data to LCD. ***/


void Lcd_Data(char lcddata)
{
IO0SET = 0x00000020; // Clear RS Pin ; It will work as data
IO0SET = lcddata << 8; // clear data line
IO0CLR = ~lcddata << 8; // Data should be shifted to 8th pin
Delay(DELAY_TINY);
Toggle_En(); // Toggle Enable pin to latch data
Delay(DELAY_250US); // Delay : To stabilize the data
}

/*** This function is used to initialize LCD. ***/


void Lcd_Init(void)
{
PINSEL0 &= ~0xFFFFFC00; // LCD 8Data pins and 3 control pins as GPIO
IO0DIR = 0x0000FFE0; // LCD is used in 4 bit mode; Pin12-15 are used for data lines
IO0CLR = 0x0000FFE0; // Pins 5,6,7 are used as control pins
IO0CLR = 0x00000040; // LCD_RW pin set for LCD write mode only

Delay(DELAY_15MS);

Lcd_Cmd(0x01); Delay(DELAY_15MS); // clear display


Lcd_Cmd(0x03); Delay(DELAY_6MS);// return home
Lcd_Cmd(0x03); Delay(DELAY_250US); // return home
Lcd_Cmd(0x03); Delay(DELAY_250US); // return home
Lcd_Cmd(0x02); Delay(DELAY_250US); // cursor home
Lcd_Cmd(0x38); Delay(DELAY_250US); // 8 BIT MODE
Lcd_Cmd(0x08); Delay(DELAY_250US); // display off
Lcd_Cmd(0x0C); Delay(DELAY_250US); // display on
Lcd_Cmd(0x06); Delay(DELAY_250US); // set entry mode
}

/*** This function is used to display string on LCD.*/


void Lcd_String(char *string)
{
while( *string != '\0' )
{
Lcd_Data(*string++); // Until NULL send data
}
}

____________________________________________________________________________
Edutech Learning Solutions Pvt. Ltd. [email protected]
Laboratory workbook for Advanced Microprocessors (As per Pune University Syllabus)

Steps to create project and program compilation:


Steps:
 Open Eclipse.exe from “C:\eclipse” folder.
 Now browse to the ARM7 Workspace under E_Workspace (in this case
C:\E_Workspace\ARM7). Click OK to continue.
 Click File > Import…, to import template.
 Click General > Existing Projects into Workspace and click Next.
 First Select Root Directory of your Eclipse Template for ARM7. Then select “Copy
projects into workspace” check box and Click Finish.
 Every time you import a project make sure to rename it. So Right Click Project >
Rename or press F2 while selecting project to rename it.
 Go to File> New > Source File and you will see New Source File Wizard. Enter Source
File name (For example main.c) then Click Finish.
 Write your code and then save your Files.
 Copy necessary .c and .h files to your local project folder. They will be added to your
project in Eclipse IDE

Steps to use hardware:

 Connect 9V DC Power supply to the educational practice board for ARM7


 Connect the board with the USB port of the PC using the USB A to B type cable.
 Using the RUN/PROGRAM mode selection switch, set the board in the program
mode. This will be indicated by the red LED.
 Apply Reset condition by pressing the RESET switch to ensure proper
communication.
 Using download tool (Flash Magic) downloads the .HEX file to the target board.
 Connect the PL3 connector of EPB ARM7 board to PC. Connect 20 pin flat cable
between J1 connector of EPBARM7 board and PL3 connector of ASK25.
 Insert SIM Card in GSM Modem and connect Power supply to it.
 Connect GSM modem to P8 connector of EPBARM7 board.
 Using the RUN/PROGRAM mode selection switch, set the board in the run mode.
This will be indicated by the green LED and apply reset to execute the program.

Result:
A call would be made via modem on the number mentioned in the program.

____________________________________________________________________________
Edutech Learning Solutions Pvt. Ltd. [email protected]

You might also like