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 GSM with LPC2148

Status
Not open for further replies.

Twisted_transistor

Member level 1
Joined
Sep 13, 2012
Messages
32
Helped
2
Reputation
4
Reaction score
1
Trophy points
1,288
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;
}
 

Hmmm,

Sounds like a IRQ issue, could be wrong though.

How are you handling the IRQ from the uart when it receives a byte(s)??

Azlan.
 

No.. I'm not interested in received bytes.. so I don't think that is a problem..
I just ignore whatever I receive..
 

Without seeing your circuit I can only guess.

Is the RX line from the GSM connected to the UART1, if so disconnect it and see what happens.

The rational is as follows:

In your code you are sending 'AT' to the GSM, the GSM will respond with <CR><LF>OK<CR><LF>

If the UART1 is generating a IRQ after receiving the above that is not handled then problem.

Again just a thought.

Cheers.
 
Last edited:
Hey Batang, Thaks alot:) you were absolutely right.. The interrupt was causing a problem.. So I disconnected the RX line fromthe GSM & the code worked fine:)
But Can you pls tell me how to handle the interrupt cause I need it for my other applications.
Thanks in advance:):)
 

Hi Twisted_transistor,

I have modified your program as follows:

1. You do not need to define character string arrays as you can put string literals in sendstring calls, so they are deleted.
2. Added a millisecond delay function using timer 0.
3. Added a UART1 IRQ on/off function.
4. Added a UART1 IRQ handler that puts incoming data into a buffer. Remember to zero out UART1_Count as required.


Please Note: The new function examples are for a NXP17xx device so therefore you may need to edit the register definitions to suite.


Cheers.

Code:
[syntax=c]#include "LPC214x.h"

#define UART1_BUFSIZE 200

volatile char UART1_Buffer[UART1_BUFSIZE] = {0};
volatile int UART1_Count = 0;

void UART1_IRQ(char state)
{
	if(state == 1)
	{
                NVIC_EnableIRQ(UART1_IRQn);
    	        LPC_UART1->IER = IER_RBR;					// Enable UART1 interrupt
	}
	else
	{
		LPC_UART1->IER = 0;						// Disable UART1 interrupt
		NVIC_DisableIRQ(UART1_IRQn);
	}
}
	
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++;
	}
}

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

void delayms(uint delay_milliseconds)
{
	#define INTERVAL_1MS	25000
	
	LPC_TIM0->TCR = 0x02;								// reset timer
	LPC_TIM0->PR  = 0x00;								// set prescaler to zero
	LPC_TIM0->MR0 = INTERVAL_1MS * delayInMs;
	LPC_TIM0->IR  = 0xFF;								// reset all interrrupts
	LPC_TIM0->MCR = 0x04;								// stop timer on match
	LPC_TIM0->TCR = 0x01;								// start timer

	while(LPC_TIM0->TC != LPC_TIM0->MR0)				// Wait until match
	
}

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

	sendstring("AT\r\n");
	delayms(100);
	IO1SET = 0x00010000;
	
	sendstring("AT+CMGF=1\r\n");
	delayms(200);
	IO1SET = 0x00040000;
	sendstring("AT+CMGS=\"+91##########\"\r\n");
	delayms(200);
	IO1CLR = 0x000F0000;
	sendstring("dips");
	senduart1(0x1A);
	delayms(100);
	IO1SET = 0x00080000;
	IO1CLR=	0x000F0000;
}

void UART1_IRQHandler(void) 
{
	#define IIR_RDA		0x02
	
	uint8_t IIRValue;
	char data = 0;
	
        IIRValue = LPC_UART1->IIR;
        IIRValue >>= 1;										// skip pending bit in IIR
        IIRValue &= 0x07;										// check bit 1~3, interrupt identification

	data = LPC_UART1->RBR;									// Read Data

  if (IIRValue == IIR_RDA)										// Receive Data Available
  {
		UART1_Buffer[UART1_Count] = data;
		UART1_Count++;
		
		if (UART1_Count == UART1_BUFSIZE) {UART1_Count = 0;}	// For Buffer Overflow
  }
}

[/syntax]
 
Last edited:

Thanks alot Batang:) I'll try it out and let u know..
We have a review 2day so hope everything goes ffine..
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top