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.

Problem interfacing LPC2148 with GSM

Status
Not open for further replies.

Twisted_transistor

Member level 1
Member level 1
Joined
Sep 13, 2012
Messages
32
Helped
2
Reputation
4
Reaction score
1
Trophy points
1,288
Visit site
Activity points
1,478
Hi.. I've written the following code for sending an SMS via the GSM module..
The code runs fine i.e. the entire code executes when the GSM is not connected to the LPC2148 board. This I can tell because I've inserted statements in the code to light LEDs so that I know till where the code has executed.

But, however, when I connect the GSM module to the board, code execution stops at the point indicated in the following code. It does not proceed further.

I've tried and tried but really cannot figure out why this is happening. Someone pls shed some light on this mystery. This is an important part of my college project.

Code:
#include "LPC214x.h"
void init(void);
extern unsigned char at[]="AT";
extern unsigned char cmgf[]="AT+CMGF=1";	                        //Text format in GSM modem
extern unsigned char cmgs[]="AT+CMGS=\"+91##########\"";           	//Mobile number to which the msg is sent
extern unsigned char msg[]="dips";								


void senduart1(unsigned char a)					//sends a byte through U1
{
U1THR=a;
while(U1LSR!=0x60);
}

void sendstring(unsigned char *p)			 //Sends a string of data through UART1
{
while(1)
{
if(*p=='\0') break;
senduart1(*p++);
}
}

void delaygsm()							  //delay function
{
int i,c=0;
for(i=0;i<4000000;i++)
{
c++;
}
}

int main()
{
PINSEL0=0x00050005;			//initialized U0 and U1 as UART and not GPIO
PINSEL1 = 0x00000000;
PINSEL2 = 0x00000000;
IO1DIR = 0xFFFFFFFF;
IO1SET = 0x000F0000;
delaygsm();
delaygsm();
delaygsm();
delaygsm();
IO1CLR = 0x000F0000; 
init();

sendstring(at);
senduart1(0x0D);							// equivalent of 
senduart1(0x0A);							//	 enter key
delaygsm();
delaygsm();
delaygsm();
delaygsm();
IO1SET = 0x00010000;                        //Code execution stops here wen GSM is connected- does not proceed further
	
sendstring(cmgf);
senduart1(0x0D);								 
senduart1(0x0A);										
delaygsm();
delaygsm();
delaygsm();
delaygsm();
IO1SET = 0x00040000;
sendstring(cmgs);
senduart1(0x0D);
senduart1(0x0A);	
delaygsm();
delaygsm();
delaygsm();
delaygsm();
IO1CLR = 0x000F0000;
sendstring(msg);
senduart1(0x1A);
delaygsm();
delaygsm();
delaygsm();
delaygsm();
IO1SET = 0x00080000;
senduart1(0x1A);
IO1CLR=	0x000F0000;
}


void init()
{

U1LCR=0x83; //8-N-1, enable divisors
U1DLL=0x62; //9600 baud (9615)
U1DLM=0x00;
U1LCR=0x03; //8-N-1, disable divisors
U1FCR=0x07;
}
 

hey.. thanks.. The problem was that I was not handling the interrupts caused by the GSM module..
Do you know how to handle the interrupts?
It would really be helpful..
 

use the following code


#include<lpc214x.h>
#include"Config.h"

#define SW1 (IO0PIN & 0x00001000)
#define SW2 (IO0PIN & 0x00002000)
#define SW3 (IO0PIN & 0x00008000) //Macro Functions to read Push button switches on LPC2148 dev. board
#define SW4 (IO0PIN & 0x40000000)

void enter(void);

void GSM_init(void) ;

void send_sms1(void);
void send_sms2(void);
void send_sms3(void);
void send_sms4(void);

#define BUZZER_ON() IO0CLR=(1<<11) //Macro Functions to turn ON Buzzer

#define BUZZER_OFF() IO0SET=(1<<11) //Macro Functions to turn OFF Buzzer

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

IODIR0= (1<<11) ;
IODIR0=(0<<12)|(0<<13)|(0<<15)|(0<<30);
BUZZER_OFF();

lcd_init();
UART1_init();

GSM_init();

lcd_cmd(0x80);

lcd_string("OBJECT IDENTIFICATION");
lcd_cmd(0xC0);

lcd_string("USING RF COMMUNI.");
Delay(400);
while(1)
{

if(!SW1 && SW2 && SW3 && SW4)
{
BUZZER_ON();
Delay(60);
BUZZER_OFF();
lcd_cmd(0x01);
lcd_cmd(0x80);
lcd_string(" OBJECT ONE ");
send_sms1();
Delay(400);
}
if(SW1 && !SW2 && SW3 && SW4)
{
BUZZER_ON();
Delay(60);
BUZZER_OFF();
lcd_cmd(0x01);
lcd_cmd(0x80);
lcd_string(" OBJECT TWO ");
send_sms2();
Delay(400);
}
if(SW1 && SW2 && !SW3 && SW4)
{
BUZZER_ON();
Delay(60);
BUZZER_OFF();
lcd_cmd(0x01);
lcd_cmd(0x80);
lcd_string(" OBJECT THREE ");
send_sms3();
Delay(400);
}
if(SW1 && SW2 && SW3 && !SW4)
{
BUZZER_ON();
Delay(60);
BUZZER_OFF();
lcd_cmd(0x01);
lcd_cmd(0x80);
lcd_string(" OBJECT FOUR ");
send_sms4();
Delay(400);
}


}

}


void GSM_init()
{
u1_print("AT");
enter();
Delay(10);
u1_print( "ATE0");
enter();
Delay(10);
u1_print("AT+CMGF=1");
enter();
Delay(10);


}

void enter()
{
u1_byte(0x0D);
u1_byte(0x0A);
}

void send_sms1()
{
u1_print("AT+CMGS=\"09214659486\"");
enter();

u1_print("Object One Detected");
u1_byte(0x1A);
lcd_cmd(0x01);
lcd_string("MSG SENT");
Delay(200);
}

void send_sms2()
{
u1_print("AT+CMGS=\"09214659486\"");
enter();
u1_print("Second Object Detected");
u1_byte(0x1A);
lcd_cmd(0x01);
lcd_string("MSG SENT");
Delay(200);
}
void send_sms3()
{
u1_print("AT+CMGS=\"9036005512\"");
enter();
u1_print("Third Object Detected");
u1_byte(0x1A);
lcd_cmd(0x01);
lcd_string("MSG SENT");
Delay(200);
}
void send_sms4()
{
u1_print("AT+CMGS=\"9036005512\"");
enter();
u1_print("Fourth Object Detected");
u1_byte(0x1A);
lcd_cmd(0x01);
lcd_string("MSG SENT");
Delay(200);
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top