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.

[SOLVED] GSM SIM900 with lpc2148

Status
Not open for further replies.

marthoma

Junior Member level 3
Joined
Oct 15, 2014
Messages
25
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
171
hiii....im working on sim908 with lpc2148 ....my problem is :my uart of lpc2148 is working fine and its sending characters(i checked dis wid hyperterminal) and my sim908 is also responding on hyperterminal to AT commands...however wen i send AT AND 0x0D now thru lpc2148 to sim908 its not responding back....
wat all cud be the reasons?i only have to attach carriage return ryt after AT??
my code gets stuck inside the get_char() where
Code:
char get_char()
{
       while(!(U0LSR & 0x01));//Wait until UART0 gets sum char  
       return U0RBR;
}

cud sumone plss help me here....
also the proper response is <cr><lf>OK<cf><lf> ryt?
 

First AT<CR> must be send with inter-character delay for the autobaud feature to work, presumed you are sending at a different baud rate than initially assumed by the modem.
 

First AT<CR> must be send with inter-character delay for the autobaud feature to work, presumed you are sending at a different baud rate than initially assumed by the modem.

sir i didnt understand ur solution....
i hav set my uart of lpc at 9600...i didnt check the preset baud rate of sim908..thank u for reminding dat...
i attached here few parts of my code...
Code:
int main()
{
	lcd_init();
	USARTInit();
	while(1)
	{	
		send_char('A');
		send_char('T');
		send_char(0x0d); //carriage return
		
		soft_delay_ms(50);
		if(!CheckGSM_Response())
		{
			continue;
		}
	}	
}
//code to send_char()

//code to receive
unsigned char buff[16];
unsigned char receive_char()
{
	int i=0;
	while(!(U0LSR&0x01));
	return U0RBR;
}	

int CheckGSM_Response()
{
		int i=0;
		int len=0;
		char data=0;
		//soft_delay_ms(10);
		while(data!='\r')
		{
			len++;
			data=receive_char();
			buff[i++]=data;
		}
		buff[i-1] = '\0';
		if(buff[0]!=0x0D | buff[1]!=0x0A)
		{	
			return 0;
		}
		if(buff[len]!=0x0D | buff[len-1]!=0x0A)
		{	
			return 0;
		}
		if((buff[2]!='O'||buff[2]!='o')&&(buff[3]!='K'||buff[3]!='k'))
		{	
			return 0;
		}	
		gotoloc(2,1);
		LCD_WriteString("received OK");
		return (1);			 		  
}

//code for uartinit()
 

i really request u all who r familiar wid sim900 to help me wid dis......is my function dat is waiting for reply doing anythng wrong???
Code:
while(data!='\r')
		{
			len++;
			data=receive_char();
			buff[i++]=data;
		}


and my code is stuck here:
Code:
while(!(U0LSR&0x01));
	return U0RBR;
 

also FvM

i checkd the baud rates...both are at 9600 or else it wudnot hav replied to hyperterminal ryt??
i had inserted "AT"in hyperterminal at 9600 and sim900 had replied "OK" to it...so baud rate is nt d problem i guess
 

I really request you to help me...im not getting the "OK"response on the lcd...where does my problem lie..i have tried alot sir...please
 

I Would suggest you setup the LPC2148 UART to received data in a IRQ service routine.

The IRQ routine then writes the incoming characters to a buffer and when a CR is received that is not the first character in the buffer set a flag that can be checked from your program main loop. If the flag is set then read the buffer for your SIM900 response string.

For ease of string compares etc I would filter out LF characters and the 1st CR in the SIM900 response string from being written to the buffer, this also allows for checking of a single CR at the end of the SIM900 response for setting the flag.

Use a terminal program on the PC to communicate with the LPC2148 for testing.

NXP has examples for a IRQ UART driver on their web site.

Cheers.

P.S. Do not forget to clear the flag and the buffer index pointer before getting another SIM900 response.
 

but what if my commands are not properly reaching the modem and which is why its nt responding den the interrupt method will also not help right?

i have read something about autobaud error...could someone explain me what it is..and could that be a problem here??should i send "at" as 'a' 't' with some delay in between??
 

should i send "at" as 'a' 't' with some delay in between??
And another delay before <CR> character. As suggested in post #2.
 

Autobauding allows the GSM engine to automatically detect the baud rate configured in the host application. The serial port of the GSM engine supports autobauding for the following baud rates: 1200, 2400, 4800, 9600, 19200, 38400 and 57600bps. Factory setting is autobauding enabled. This gives you the flexibility to put the GSM engine into operation no matter what baud rate your host application is configured to. To take advantage of autobauding mode, specific attention should be paid to the following requirements:

SIM900 Synchronization between DTE and DCE:

When DCE powers on with the autobauding enabled (Default), user must first send “AT” to synchronize the baud rate. It is recommended to wait 2 to 3 seconds before sending “AT” character. After receiving the “OK” response, DTE and DCE are correctly synchronized. The more information please refer to the AT command “AT+IPR”.

Restrictions on autobauding operation.

1) The serial port has to be operated at 8 data bits, no parity and 1 stop bit (factory setting).

2) The Unsolicited Result Codes like "RDY", "+CFUN: 1" and "+CPIN: READY” are not indicated when you start up the ME while autobauding is enabled. This is due to the fact that the new baud rate is not detected unless DTE and DCE are correctly synchronized as described above.

Note: User can use “AT+IPR=x” to set a fixed baud rate and save the configuration to non-volatile flash memory. After the configuration is saved as fixed baud rate, the Unsolicited Result Codes like "RDY" should be received from the serial port every time that the SIM900 is powered on.

Cheers.
 

Okay i get it....i tried with 'a' delay 't' delay '0x0d'...still im not getting the response...could you please check my code and tel me how to solve the problem using polling...i dont want to use interrupts as of now..i wanted to try using polling method itself..i have attached my code again..please do check

Code:
#include<lpc214x.h>
#include<stdlib.h>
#include<string.h>
#include<stdio.h>
#include "lcd.h"

void send_string(char *p);//Sends a string of data through UART1
void send_char(char data);
void USARTInit(void);
unsigned char receive_char(void);

int main()
{
	char ch[16]="";
	int i=0;
	lcd_init();
	USARTInit();
	gotoloc(1,1);
	LCD_WriteString("welcome to gsm");
	soft_delay_ms(1000);
	while(1)
	{	
		LCD_Cmd(0x01);
		soft_delay_ms(100);
		//sending AT command
		LCD_WriteString("sending AT");
		
		U0FCR=0x04;
		send_char('A');
		soft_delay_ms(10);
		send_char('T');
		//soft_delay_ms(10);
		send_char(0x0d); //carriage return
		while(ch[i]!='\r')
		{
			ch[i]=receive_char();
			
			LCD_Write_DATA(ch[i++]);
		}	
		//send_char(0x0a);//line feed
	}	
}

void send_char(char data)
{
	while(!(U0LSR&0x20));
	U0THR=data;
}

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

unsigned char receive_char()
{
	while(!(U0LSR&0x01));
	gotoloc(2,1);
	LCD_WriteString(" 2 ");
	return U0RBR;
}	

void USARTInit()
{
	PINSEL0 = 0x00000005;  //Select TxD    for     P0.0 and RxD for P0.1
  U0LCR   = 0x83;// 8 bits, no Parity, 1 Stop bit  
	U0DLM   = 0x00;
	U0DLL   = 0x61;
	U0FCR	  = 0X07;//ENABLE FIFO
	U0TER   = 0X80;
	U0LCR   = 0x03;//to lock mul  and div value

}

- - - Updated - - -

is there any regioster that i have to enable to receive anything apart from what i have done....i enabled 1)U0TER FOR tx transmission
2)U0FCR for fifo enable....my mc is not receiving anything basically
 

hiii....i hv finally solved the problem...message gets delivered now!!! :)...but the message received also contains the echo response and OK response along wid it....i.e.if the message set was "hello" den i also get at,at+cmgf=1,at+cmgs+....."hello
 

Send the command ATE0 to the GSM modem to turn off echo.

You can either issue this command as part of the GSM modem initialization or send it once and then send AT&W command to make it permanent. You can always reverse it by sending ATE1 and them AT&W.

I highly recommend that you read the SIM900 AT command manual.

Cheers.
 

Hey hiii...I gt d probpem solved it too...it was just a dely probpem..thanku a lot to pl....im so relieved
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top