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] problem in receiving response from GSM modem

Status
Not open for further replies.

kirtan

Junior Member level 2
Joined
Mar 11, 2011
Messages
20
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,515
I am trying to interface SIM300 GSM modem with LPC2148.
When i send an at command to modem, i get the echo of command send. But after sending '\r' at the end of the AT command i do not get the response.

To illustrate the problem part of interest in the code is as follows

send_string("AT+CREG?");
sendchar('\r');
buf_rx=read_string();

These are functions with dedicated code for sending string, character and reading string written.

buf_rx received is displayed on the LCD display available on the kit

The buf_rx in above case shows AT+CREG? followed by Ascii character for \r.

When i check the modem on hyperterminal it works normal.

Kindly help me to know why do i not receive the response following the command.

thanks in advance

Kirtan
 

When i send an at command to modem, i get the echo of command send. But after sending '\r' at the end of the AT command i do not get the response.

When i check the modem on hyperterminal it works normal.

It's hard to say without the code. Even with the code could be tricky.
If you see it in hyperterminal but not get it from the code, then there is something with the program.
How does this buf_rx=read_string(); works? Waits until all bytes are received? From interrupt or polling?
In which way you can see the bytes received from LPC2148? Are you using a debugger?
 

It's hard to say without the code. Even with the code could be tricky.
If you see it in hyperterminal but not get it from the code, then there is something with the program.
How does this buf_rx=read_string(); works? Waits until all bytes are received? From interrupt or polling?
In which way you can see the bytes received from LPC2148? Are you using a debugger?

Thanks Alexxx for showing up the interest..
Here are some of more details ...

1) Polling method is used for serial communication
LPC2148 supports internal FIFO of 16 bytes for serial communication and in this program i have enabled it....


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
buf_rx=read_string() is coded as follows
 
char *read_string(void){
static char buf_rx1[50]="";
int i;
unsigned char x=0;
while (!(U0LSR & 0x01));                        //wait for the response to come
  do                                    //read if character is available and pass time to ensure full data to be received
  {
    if((U0LSR & 0x01))                  //this count (i) actual depends on the serial baud rate and cpu clock  can 
    { 
        buf_rx1[x++]=U0RBR;             //count i roughly > CCLK/UART baud rage
        i=0;                            //60^6/9615 approx 6000
    }
    else
    {
      i++;
    }
  }while(i<6000);   
   return(buf_rx1);            
  }



2) To see the bytes received: There is a code in the program that display the data received on local LCD attached with controller (this is for debugging purpose).

As I have mentioned in my previously, from GSM modem i get the echo of command sent ie if i send "AT+CREG?" i receive the same and can see on LCD "AT+CREG?"
But after sending '\r' at the end of the AT command i do not get the response.

i have also checked sending 0x0d (hex equivalent of '\r') but does not work

Kindly help to point out the mistake...

thanks
 
Last edited by a moderator:

2) To see the bytes received: There is a code in the program that display the data received on local LCD attached with controller (this is for debugging purpose).

As I have mentioned in my previously, from GSM modem i get the echo of command sent ie if i send "AT+CREG?" i receive the same and can see on LCD "AT+CREG?"
But after sending '\r' at the end of the AT command i do not get the response.

i have also checked sending 0x0d (hex equivalent of '\r') but does not work
0x0D is not a printable ASCII character. If I remember correrctly it occupies a space in a character LCD, where custom characters can be written.
 
Last edited:

I agree with you that 0x0D is not a printable ASCII character.
However when i send the command "AT+CREG?" followed by '\r'
I should get the response something like +CREG:0, 1 <CR> <LF> OK, which i am unable to get from modem.
When i give the same command from hyperterminal I receive the response.

I have tried to receive the response by reading serial port in more then one way with small and large delays....with and without enabling inbuilt FIFO, but could not succeed.

I am badly stuck with this...can't move forward.

kindly help....
Special thanks to alexx for the interest.
 

As a first step you should check, if the processor is actually sending the intended command and if the GSM modem is responding to it. This would if the problem is related to send respectively talking to the modem or on receive. You also can check the receive routine with a different peer, e.g. hyperterminal.

Sharing a "popular" fault in modem communiction, your code isn't able to trigger the modem's autobaud function. This won't be a problem, if it's using the default baud rate. Otherwise you would want to send initially separate "A" "T" characters with a short surrounding delay as required by the autobaud function. If you think about it, you surely understand why.
 

Thanks for the interest shown...

Modem works fine and as expected when checked using hyper terminal.

To check whether i receive response from the modem i have written a small routine as follows:
The code simply initialize lcd and serial port (this is fine as i get expected behaviour from both). Then I try to send a simple "AT/r" to modem.


When microcontroller kit is connected with hyper terminal the code behaves as expected i.e. when we responding to microcontroller on HT as modem .

But when connected with microcontroller, (as seen in code)

step1: I send 'A' and i get it back from modem, and display it on LCD
setp2: I send 'T' and i get it back from modem, and display it on LCD
setp3: I send '\r' and i get it back from modem, and display it on LCD
setp4: I wait for the response to AT command i.e. <LF>OK<CR><LF>, but it seems MC stays there for infinite time waiting for the response and then after nothing is displayed on LCD

//------------------------------------------------------------
int main (void){
init_lcd();
init_serial ();
init_gsm_modem();
while(1);
}
//------------------------------------------------------------


//------------------------------------------------------------

void init_gsm_modem (void) {
char check;

lcd_command(0x80);
printlcd("AT\r");

check = gsm_command("AT"); //send at command

}
//------------------------------------------------------------

char gsm_command(char *CPtr){

char temp,temp1=0x42,temp2=0x42,temp3=0x42, temp4=0x42; //initialized with dummy value
char check=1;
char i=0xC0; // point to first location in LCD
while(*CPtr != '\0') {
sendchar(*CPtr);
temp = getchar();
lcd_command(i++);
lcd_data(temp); //display the received the echo of command sent
if (temp!=*CPtr){
check=0x00;
break;
}
CPtr++;
}

sendchar('\r'); //after AT send ‘\r’
temp = getchar();
lcd_command(i++);
lcd_data(temp);

while (!(U0LSR & 0x01)); //wait for the response expected <LF>OK<CR><LF>
temp1 = getchar();
while (!(U0LSR & 0x01));
temp2 = getchar();
while (!(U0LSR & 0x01));
temp3 = getchar();
while (!(U0LSR & 0x01));
temp4 = getchar();

lcd_command(0xC4); ;display what is received
lcd_data(temp1);
lcd_command(0xc5);
lcd_data(temp2);
lcd_command(0xc6);
lcd_data(temp3);
lcd_command(0xc7);
lcd_data(temp4);
return(check);
}
 

Yes I do. I receive A, T and \r which are displayed on LCD but after that i do not receive anything.
 

hi kirtan i'm also facing same problem when interfacing with 8051 with sim300 gsm modem....
the modem is working fine with hyper terminal...
but not with 8051.. pls let me know where i'm wrong...
 

the problem is in ur code i guess. why dont you make a simple test software
Code:
use this algo ::

initialize micro and gms module
initialize lcd
initialize usart

while (1)
{
write_char_to_lcd(USART_recieve)
}

now call the system .LCD should display something there..
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top