Discussion in "Embedded GSM Development" started by    07arunsharma    Feb 6, 2013.
Wed Feb 06 2013, 03:37 pm
#1
Hello!! I successfully transmit data to a TCP server using SIM300 Module using Windows Hyper terminal.
But i have to automate this process.

But not able to write code for it, don't know why i am not able to receive data from GPRS Module properly.

Can any one share an algorithm to send command to gprs module and based on the received data i can process further.

Please help

Wed Feb 06 2013, 04:15 pm
#2
@ 07arunsharma
whats AT commands set u use
that at commands has to be sent to modem using micro controller serial port
before that u need a serial port coding in pic
you can see that in tutorial section
Wed Feb 06 2013, 04:30 pm
#3
every response from simcom start with 0x0D0x0AOK0x0D0x0A you can put some check on 0x0D0x0A
this is how you can receive a complete packet
Wed Feb 06 2013, 04:36 pm
#4
Pls have a look at the code

#include<p18f8722.h>

#include<delays.h>


/************Configuration Bits*************/
#pragma config OSC = HSPLL
#pragma config FCMEN = OFF
#pragma config IESO = OFF
#pragma config PWRT = OFF
#pragma config WDT = OFF
#pragma config LVP = OFF
#pragma config XINST =OFF
/*******************************************/

/****************PIN DETAILS****************/
#define LCD_RS	PORTGbits.RG2
#define LCD_RW	PORTGbits.RG1
#define LCD_EN	PORTGbits.RG0
#define LCD_DATA LATE
#define LCD_CLEAR 0x01
#define FIRST_ROW 0x80
#define SECOND_ROW 0xC0
#define ROM_MSG_SIZE 40
/*******************************************/

/******************Function Prototypes*****************/
void Delay_ms(unsigned int time);
void Delay_1us(void);
void UART1_Init(void);
void UART1_Write(unsigned char value);
void UART1_Write_Text(unsigned char msg[]);
unsigned char UART1_Read(void);
void Lcd_Init(void);
void Lcd_Cmd(unsigned char value);
void Lcd_Write(unsigned char value);
void Lcd_Write_Text(unsigned char msg[]);
unsigned char * CopyConstToRAM(unsigned char * dest,const rom unsigned char * src);
void Clear_Serial_Buffer(void);
void Correct_Serial_Errors(void);
unsigned char Compare_String(unsigned char *first,unsigned char *second);
/********************************************************/

const rom unsigned char company[] = "COMPANY NAME";
const rom unsigned char Echo_Off[] = "ATE0\r\n";
const rom unsigned char gprs_shutdown[] = "AT+CIPSHUT\r";
const rom unsigned char gprs_shutdown_again[] = "AT+CGATT=0\r\n";
const rom unsigned char attach_gprs[] ="AT+CGATT=1\r";
const rom unsigned char pdp_context[] = "AT+CGDCONT=1,\"IP\",\"airtelgprs.com\"\r";
const rom unsigned char set_apn[] = "AT+CSTT=\"airtelgprs.com\",\"\",\"\"\r";
const rom unsigned char bring_wireless[] = "AT+CIICR\r";
const rom unsigned char get_ip[] = "AT+CIFSR\r";
const rom unsigned char ip_status[] = "AT+CIPSTATUS\r";
const rom unsigned char dns_or_ip[] = "AT+CDNSORIP=0\r";
const rom unsigned char start_connection[] = "AT+CIPSTART=\"TCP\",\"59.161.80.11\"\r";
const rom unsigned char send_data_command[] = "AT+CIPSEND\r\n";

unsigned char rom_msg[ROM_MSG_SIZE],i,temp;
unsigned char Serial_Data[100];
unsigned long Serial_Timeout=0;


void main()
{
	unsigned char flag = 0;
	unsigned char OK_Reply[] = "OK";
	unsigned char IPSTATE_Reply[] = "STATE:IP STATUS";
	unsigned char START_Reply[] = "CONNECT OK";
	unsigned char SENDOK_Reply[] = "SEND OK";
	unsigned char rockstar;
	rockstar = 0;
	
    INTCONbits.GIE = 1;
    INTCONbits.GIEL = 1;
    i=0;
    Lcd_Init();
    UART1_Init();
    CopyConstToRAM(rom_msg,company);
    //UART1_Write_Text(rom_msg);
    UART1_Write('A');
    UART1_Write('T');
    Lcd_Write_Text(rom_msg);
    
    Delay_ms(1000);
    
    do
    {
	    while(1)
	    {
	    /*******************************************************/
	    Correct_Serial_Errors();
	    Clear_Serial_Buffer();						//Clear Serial Data befor Proceeding further
	    CopyConstToRAM(rom_msg,Echo_Off);			//Echo Off Command, Otherwise Controller will also receive the Characters Typed
	    UART1_Write_Text(rom_msg);
	    /*******************************************************/
	    
	    Delay_ms(500);
	    
	    /*******************************************************/
	    if(flag != 0)
	    {
	    	Clear_Serial_Buffer();
	    	CopyConstToRAM(rom_msg,gprs_shutdown);		//Shut Down GPRS Befor Proceeding
	    	Correct_Serial_Errors();					//Correct Serial Errors if Any
	    	i=0;
	    	UART1_Write_Text(rom_msg);					//Receive Data received after getting AT+CIPSHUT Command
	    	do
	    	{		    
		    	//Correct_Serial_Errors();
		    	Serial_Data[i] = UART1_Read();
		    	if(Serial_Data[0] == 0x0D & Serial_Data[1] == 0x0A)
		    	{
			    	i=0;
				}
				else
				{
					i++;
				}		    
			}while(Serial_Data[i-1] != 0x0A & Serial_Data[i-2] != 0x0D);	
			Serial_Data[i-1] = Serial_Data[i-2] = '\0';		//Replace Line Feed and Carriage Return by NULL character,to display it on LCD
			Lcd_Cmd(LCD_CLEAR);
			Lcd_Write_Text(Serial_Data);					//Display the Receive Data on LCD		
		
			Delay_ms(500);
		
			Clear_Serial_Buffer();
		    CopyConstToRAM(rom_msg,gprs_shutdown_again);		//Shut Down GPRS Befor Proceeding
		    Correct_Serial_Errors();					//Correct Serial Errors if Any
		    i=0;
		    UART1_Write_Text(rom_msg);					//Receive Data received after getting AT+CGATT=0 Command
		    do
		    {
			    
			    //Correct_Serial_Errors();
			    Serial_Data[i] = UART1_Read();
			    if(Serial_Data[0] == 0x0D & Serial_Data[1] == 0x0A)
			    {
				    i=0;
				}
				else
				{
					i++;
				}
			    
			}while(Serial_Data[i-1] != 0x0A & Serial_Data[i-2] != 0x0D);	
			Serial_Data[i-1] = Serial_Data[i-2] = '\0';		//Replace Line Feed and Carriage Return by NULL character,to display it on LCD
			Lcd_Cmd(LCD_CLEAR);
			Lcd_Write_Text(Serial_Data);					//Display the Receive Data on LCD
		}		
		/*******************************************************/
		
		Delay_ms(500);
		
		/*******************************************************/
		Clear_Serial_Buffer();							//Clear Serial Buffers, befor Proceeding further
		Correct_Serial_Errors();						//Correct Serial Errors if any
	    CopyConstToRAM(rom_msg,attach_gprs);			//Send AT+CGATT=1 Command, to attach with GPRS Module
	    i=0;
	    UART1_Write_Text(rom_msg);
	    do
	    {
		    //Correct_Serial_Errors();
		    Serial_Data[i] = UART1_Read();
		    if(Serial_Data[0] == 0x0D | Serial_Data[1] == 0x0A)
		    {
			    i=0;
			}
			else
			{
				i++;
			}
		}while(Serial_Data[i-1] != 0x0A & Serial_Data[i-2] != 0x0D);
		Serial_Data[i-1] = Serial_Data[i-2] = '\0';		//Replace Line Feed and Carriage Return by NULL character,to display it on LCD
		Lcd_Cmd(LCD_CLEAR);
		Lcd_Write_Text(Serial_Data);					//Display Received data on LCD
		
		//////////////////////////////////////////////////
		if(Compare_String(Serial_Data,OK_Reply) != 0)		//This will return 0 if comparision is 'O' and if not will return '1'
		{
			flag++;
			break;
			//Start Again, as GPRS ATTACH Command didn't work
		}
		flag = 0;		//As Attach GPRS Command works Properly
		//////////////////////////////////////////////////
		/*******************************************************/	
		
		Delay_ms(500);
		
		/*******************************************************/
		Correct_Serial_Errors();
	    Clear_Serial_Buffer();							//Clear Serial Buffers
	    CopyConstToRAM(rom_msg,pdp_context);			//Send AT+CGDCONT=1,"IP","APN Name" command to GPRS Module to define PDP Context
	    i=0;
	    UART1_Write_Text(rom_msg);
	    do
	    {
		    //Correct_Serial_Errors();
		    Serial_Data[i] = UART1_Read();
		    if(Serial_Data[0] == 0x0D | Serial_Data[1] == 0x0A)
		    {
			    i=0;
			}
			else
			{
				i++;
			}
		}while(Serial_Data[i-1] != 0x0A & Serial_Data[i-2] != 0x0D);
		Serial_Data[i-1] = Serial_Data[i-2] = '\0';		//Replace Line Feed and Carriage Return by NULL character,to display it on LCD
		Lcd_Cmd(LCD_CLEAR);
		Lcd_Write_Text(Serial_Data);					//Display Received Data on LCD
	    /*******************************************************/           
	    
	    Delay_ms(500);
	    
	    /*******************************************************/
	    Correct_Serial_Errors();
	    Clear_Serial_Buffer();							//Clear Serial Buffers
	    CopyConstToRAM(rom_msg,set_apn);				//Set APN Name, User Name and Password, it depends on your Network
	    i=0;
	    UART1_Write_Text(rom_msg);						//AT+CSTT="APN NAME","USER NAME","PASSWORD"
		do
	    {
		    //Correct_Serial_Errors();
		    Serial_Data[i] = UART1_Read();
		    if(Serial_Data[0] == 0x0D | Serial_Data[1] == 0x0A)
		    {
			    i=0;
			}
			else
			{
				i++;
			}
		}while(Serial_Data[i-1] != 0x0A & Serial_Data[i-2] != 0x0D);
		Serial_Data[i-1] = Serial_Data[i-2] = '\0';		//Replace Line Feed and Carriage Return by NULL character,to display it on LCD
		Lcd_Cmd(LCD_CLEAR);
		Lcd_Write_Text(Serial_Data);					//Display Received Data on LCD
		/*******************************************************/
		
		Delay_ms(500);
		
		/*******************************************************/
		Correct_Serial_Errors();
	    Clear_Serial_Buffer();
	    CopyConstToRAM(rom_msg,bring_wireless);			//Send AT+CIICR Command to GPRS Module, to bring the Wireless Connection
	    i=0;
	    UART1_Write_Text(rom_msg);						//If this command returns OK thens proceed further, otherwise Start again
	    do
	    {
		    //Correct_Serial_Errors();
		    Serial_Data[i] = UART1_Read();
		    if(Serial_Data[0] == 0x0D | Serial_Data[1] == 0x0A)
		    {
			    i=0;
			}
			else
			{
				i++;
			}
		}while(Serial_Data[i-1] != 0x0A & Serial_Data[i-2] != 0x0D);
		Serial_Data[i-1] = Serial_Data[i-2] = '\0';		//Replace Line Feed and Carriage Return by NULL character,to display it on LCD
		Lcd_Cmd(LCD_CLEAR);
		Lcd_Write_Text(Serial_Data);					//Display Received Data on LCD
		
		//////////////////////////////////////////////////
		if(Compare_String(Serial_Data,OK_Reply) != 0)		//This will return 0 if comparision is 'O' and if not will return '1'
		{
			flag++;
			break;
			//Start Again, as AT+CIICR Command didn't work
		}
		flag = 0;
		//////////////////////////////////////////////////
		/*******************************************************/
		
		Delay_ms(500);
		
	    /*******************************************************/
	    Correct_Serial_Errors();
	    Clear_Serial_Buffer();
	    CopyConstToRAM(rom_msg,get_ip);					//AT+CIFSR will return the IP Address of the Module
	    i=0;
	    UART1_Write_Text(rom_msg);
	    do
	    {
		    //Correct_Serial_Errors();
		    Serial_Data[i] = UART1_Read();
		    if(Serial_Data[0] == 0x0D | Serial_Data[1] == 0x0A)
		    {
			    i=0;
			}
			else
			{
				i++;
			}
		}while(Serial_Data[i-1] != 0x0A & Serial_Data[i-2] != 0x0D);
		Serial_Data[i-1] = Serial_Data[i-2] = '\0';		//Replace Line Feed and Carriage Return by NULL character,to display it on LCD
		Lcd_Cmd(LCD_CLEAR);
		Lcd_Write_Text(Serial_Data);					//Display Received Data thats is IP Address on LCD
		/*******************************************************/
		
		Delay_ms(500);
		
		/*******************************************************/
		Correct_Serial_Errors();
	    Clear_Serial_Buffer();
	    CopyConstToRAM(rom_msg,ip_status);				//Get State of IP, it must return STATE:IP STATUS for proper Operation, otherwise Start again
	    i=0;
	    UART1_Write_Text(rom_msg);
	    do
	    {
	        //Correct_Serial_Errors();
		    Serial_Data[i] = UART1_Read();
		    if(Serial_Data[0] == 0x0D | Serial_Data[1] == 0x0A)
		    {
			    i=0;
			}
			else
			{
				i++;
			}			
	    }while(Serial_Data[i-1] != 0x0A & Serial_Data[i-2] != 0x0D);
	    Serial_Data[i-1] = Serial_Data[i-2] = '\0';		//Replace Line Feed and Carriage Return by NULL character,to display it on LCD
	    Lcd_Cmd(LCD_CLEAR);
	    Lcd_Write_Text(Serial_Data);					//Display Received Data on LCD i.e "STATE:IP STATUS"
	    
	    //////////////////////////////////////////////////
		if(Compare_String(Serial_Data,IPSTATE_Reply) != 0)		//This will return 0 if comparision is 'O' and if not will return '1'
		{
			flag++;
			break;
			//Start Again, as IP STATE doesn't match the desired IP STATUS
		}
		flag = 0;
		//////////////////////////////////////////////////
	    /*******************************************************/
	    
	    Delay_ms(500);
	    
	    /*******************************************************/
	    Correct_Serial_Errors();
	    Clear_Serial_Buffer();
	    CopyConstToRAM(rom_msg,dns_or_ip);				//AT+CDNSORIP=0 or AT+CDNSORIP=1, 0 means IP and 1 means Domain Name
	    UART1_Write_Text(rom_msg);
	    i=0;
	    do
	    {
	        //Correct_Serial_Errors();
		    Serial_Data[i] = UART1_Read();
		    if(Serial_Data[0] == 0x0D | Serial_Data[1] == 0x0A)
		    {
			    i=0;
			}
			else
			{
				i++;
			}
	    }while(Serial_Data[i-1] != 0x0A & Serial_Data[i-2] != 0x0D);
	    Serial_Data[i-1] = Serial_Data[i-2] = '\0';		//Replace Line Feed and Carriage Return by NULL character,to display it on LCD
	    Lcd_Cmd(LCD_CLEAR);
	    Lcd_Write_Text(Serial_Data);					//Display Received data on LCD
	    /*******************************************************/
	    
	    Delay_ms(500);
	    
	    /*******************************************************/
	    Clear_Serial_Buffer();
	    CopyConstToRAM(rom_msg,start_connection);		//Start TCP Connection AT+CIPSTART="TCP","IP Address or Domain Name","PORT NUMBER"
	    UART1_Write_Text(rom_msg);
	    i=0;
	    do
	    {
	        //Correct_Serial_Errors();
		    Serial_Data[i] = UART1_Read();
		    if(Serial_Data[0] == 0x0D | Serial_Data[1] == 0x0A)
		    {
			    i=0;
			}
			else
			{
				i++;
			}
	    }while(Serial_Data[i-1] != 0x0A & Serial_Data[i-2] != 0x0D);
	    Serial_Data[i-1] = Serial_Data[i-2] = '\0';		//Replace Line Feed and Carriage Return by NULL character,to display it on LCD
	    Lcd_Cmd(LCD_CLEAR);
	    Lcd_Write_Text(Serial_Data);					//Display Received Data on LCD
	    //////////////////////////////////////////////////
		if(Compare_String(Serial_Data,OK_Reply) != 0)		//This will return 0 if comparision is 'O' and if not will return '1'
		{
			flag++;
			break;
			//Start Again, as TCP Connection Command didn't work
		}
		flag = 0;
		//////////////////////////////////////////////////
	    //The Data Received here will be OK, But we have to wait for "CONNECT OK", even then we can send data otherwise not
	    /*******************************************************/
		Correct_Serial_Errors();
		Clear_Serial_Buffer();
	    i=0;
	    do
	    {
	        //Correct_Serial_Errors();
		    Serial_Data[i] = UART1_Read();
		    if(Serial_Data[0] == 0x0D | Serial_Data[1] == 0x0A)
		    {
			    i=0;
			}
			else
			{
				i++;
			}
	    }while(Serial_Data[i-1] != 0x0A & Serial_Data[i-2] != 0x0D);
	    Serial_Data[i-1] = Serial_Data[i-2] = '\0';
	    Lcd_Cmd(SECOND_ROW);
	    Lcd_Write_Text(Serial_Data);
	    
	    //////////////////////////////////////////////////
		if(Compare_String(Serial_Data,START_Reply) != 0)		//This will return 0 if comparision is 'O' and if not will return '1'
		{
			flag++;
			break;
			//Start Again, as TCP Connection not Started
		}
		flag = 0;
		//////////////////////////////////////////////////
	    /*******************************************************/
	    
	    Delay_ms(500);
	    
	    /*******************************************************/
	    Correct_Serial_Errors();
	    Clear_Serial_Buffer();
	    i=0;
	    CopyConstToRAM(rom_msg,send_data_command);		//Start to Send data using AT+CIPSEND Command
	    UART1_Write_Text(rom_msg);
	    do
	    {
	        //Correct_Serial_Errors();
		    Serial_Data[i] = UART1_Read();
		    if(Serial_Data[0] == 0x0D | Serial_Data[1] == 0x0A)
		    {
			    i=0;
			}
			else
			{
				i++;
			}
	    }while(Serial_Data[i-1] != '>
');
	    //Send Data to TCP Server
	    UART1_Write('A');
	    UART1_Write('R');
	    UART1_Write('U');
	    UART1_Write('N');
	    UART1_Write(0x1A);
	    rockstar = 1;
	    Delay_ms(100);
	    if(rockstar == 1)
	    {
		    break;
	    }
	}
	}while(rockstar == 0);
	
	while(1)
	{
		Clear_Serial_Buffer();
	    i=0;
	    CopyConstToRAM(rom_msg,send_data_command);		//Start to Send data using AT+CIPSEND Command
	    UART1_Write_Text(rom_msg);
	    do
	    {
	        //Correct_Serial_Errors();
		    Serial_Data[i] = UART1_Read();
		    if(Serial_Data[0] == 0x0D | Serial_Data[1] == 0x0A)
		    {
			    i=0;
			}
			else
			{
				i++;
			}
	    }while(Serial_Data[i-1] != '>
');
	    //Send Data to TCP Server
	    UART1_Write('A');
	    UART1_Write('R');
	    UART1_Write('U');
	    UART1_Write('N');
	    UART1_Write(0x1A);
	    Clear_Serial_Buffer();
	    i=0;
	    do
	    {
		    //Correct_Serial_Errors();
		    Serial_Data[i] = UART1_Read();
		    if(Serial_Data[0] == 0x0D | Serial_Data[1] == 0x0A)
		    {
			    i=0;
			}
			else
			{
				i++;
			}
		}while(Serial_Data[i-1] != 0x0A & Serial_Data[i-2] != 0x0D);
		Serial_Data[i-1] = Serial_Data[i-2] = '\0';		//Replace Line Feed and Carriage Return by NULL character,to display it on LCD
		Lcd_Cmd(LCD_CLEAR);
		Lcd_Write_Text(Serial_Data);					//Display Received Data on LCD	    
	    Delay_ms(1000);
	}
    //End of Program
}

/**************Function Definitions*************/
void Delay_ms(unsigned int time)
{
#ifndef __DELAY_IN_SEC
    #define __DELAY_IN_SEC
    unsigned int first;
    unsigned int second;
#endif
    for(first=0;first<time;first++)
    {
        for(second=0;second<600;second++)
        {
            Delay1TCY();
        }
    }
}
void Delay_1us()
{
    Delay1TCY();
    Delay1TCY();
    Delay1TCY();
    Delay1TCY();
    Delay1TCY();
    Delay1TCY();
    Delay1TCY();
}
void Lcd_Cmd(unsigned char value)
{
    LCD_DATA = value;
    LCD_RS = 0;
    LCD_RW = 0;
    LCD_EN = 1;
    Delay_ms(1);
    Delay_ms(1);
    LCD_EN = 0;
    Delay_ms(1);
}
void Lcd_Write(unsigned char value)
{
    LCD_DATA = value;
    LCD_RS = 1;
    LCD_RW = 0;
    LCD_EN = 1;
    Delay_ms(2);
    LCD_EN = 0;
    Delay_ms(1);
}

void Lcd_Write_Text(unsigned char msg[])
{
    while(*msg)
    {
        Lcd_Write(*msg);
        msg++;
    }
}

void Lcd_Init(void)
{
    TRISE = 0x00;
    TRISGbits.TRISG0 = 0;
    TRISGbits.TRISG1 = 0;
    TRISGbits.TRISG2 = 0;
    Lcd_Cmd(0x38);      //Lcd_Initialize
    Delay_ms(10);
    Lcd_Cmd(0x38);      //Lcd_Initialize
    Delay_ms(10);
    Lcd_Cmd(0x0C);
    Delay_ms(10);
    Lcd_Cmd(0x01);
    Delay_ms(10);
    Lcd_Cmd(0x80);
    Delay_ms(10);
}
void UART1_Init()
{
    TRISCbits.TRISC7 = 1;
    TRISCbits.TRISC6 = 1;

    //Transmitting Setting
    TXSTA1 = 0x22;	//Transmit Enable Bit and TSR Empty	and Low Speed

    //Reception Setting
    RCSTA1bits.SPEN = 1;		//Serial Port Enable Bit
    RCSTA1bits.CREN = 1;		//Continous Receive Enable bit

    //Baud Rate Control Bit
    BAUDCON1bits.BRG16 = 0;//		//8-Bit Baud Rate Generator
    TXSTAbits.BRGH = 0;				//Low Baud Speed Mode

    //Baud Rate = 9600bps
    SPBRG = 64;		//Only for 40Mhz Crystal in PIC18F8722
}
void UART1_Write(unsigned char value)
{

    while(PIR1bits.TX1IF == 0);	//Wait Until Flag Gets Set
    TXREG1 = value;
}

void UART1_Write_Text(unsigned char msg[])
{
    while(*msg)
    {
        UART1_Write(*msg);
        msg++;
    }
}
unsigned char UART1_Read()
{
    //Correct_Serial_Errors;
    while(PIR1bits.RC1IF == 0);		//Wait for a byte
    return RCREG1;
}
unsigned char * CopyConstToRAM(unsigned char * dest,const rom unsigned char * src)
{
    for(i=0;i<ROM_MSG_SIZE;i++)
    {
        rom_msg[i] = 0;
    }
    for(;*dest++=*src++;)
        ;
    return dest;
}
void Clear_Serial_Buffer()
{

    unsigned int variable;

    for(variable=0;variable<100;variable++)
    {
        Serial_Data[variable] = 0;
    }
}
void Correct_Serial_Errors()
{
    if(RCSTA1bits.OERR == 1)
    {
        RCSTA1bits.CREN = 0;
        RCSTA1bits.CREN = 1;
    }
}
unsigned char Compare_String(unsigned char *first,unsigned char *second)
{
	/*
	Using this technique to Compare String we greatly reduced the code size by many bytes
	*/
	while(*first == *second)
	{
		if(*first == '\0' || *second == '\0')
			break;
		first++;
		second++;		
	}
	if(*first == '\0' && *second == '\0')
		return 0;
	else
		return 1;		
}
/**********************************************/


[ Edited Wed Feb 06 2013, 04:46 pm ]
Wed Feb 06 2013, 04:39 pm
#5
The commands i used are as follow:-

"ATE0\r"
""AT+CGDCONT=1,"IP","airtelgprs.com"\r"
AT+CSTT="airtelgprs.com"
AT+CIICR
AT+CIFSR
AT+CIPSTATUS
AT+CDNSORIP=0

You can check my code
But the problem is that my OERR bit sets and this stops my all communication, i dont know why this happens.
Wed Feb 06 2013, 07:54 pm
#6
To understand the entire code is bit difficult. Please point out where exactly the issue is So that you ll save time of us to understand entire thing.
Have you checked this link.
http://www.8051projects.net/t53769-p10/embedded-gsm-development/gprs-8051.htm

Wed Feb 06 2013, 08:31 pm
#7
Hello!!! Actually i solved my problem, but still wants to know why this happen.

Those who are familiar with pic micro-controller knows that, der is a bit OERR in RCSTA register which sets it self when der is over run problem.
And Stops Communication.

This is the problem i am facing.


do
                    {
                           
                            //Correct_Serial_Errors();
                            Serial_Data[i] = UART1_Read();
                            if(Serial_Data[0] == 0x0D & Serial_Data[1] == 0x0A)
                            {
                                    i=0;
                                }
                                else
                                {
                                        i++;
                                }
                           
                        }while(Serial_Data[i-1] != 0x0A & Serial_Data[i-2] != 0x0D);


This routine is causing the problem, dont know why
I changed it to
do
                    {
                           
                            //Correct_Serial_Errors();
                            Serial_Data[i++] = UART1_Read();
                            if(Serial_Data[0] == 0x0D)
                            {
                                    i=0;
                            }
                            if(Serial_Data[0] == 0x0A)
                            {
                                    i=0;
                            }
                        }while(Serial_Data[i-1] != 0x0A & Serial_Data[i-2] != 0x0D);


And it starts working
:-)

Let me tell you what i am doing.

I send command, and when its response come, i check whether it is appropriate and then send command again.

If there is any error i start again.

But still der are some problem.
Which i think due to that, i had not read sim300 manual properly
Wed Feb 06 2013, 08:39 pm
#8
I want to ask some thing more.

I am making a data logger project,
where i have to send all logging data to a TCP Server, this is what i want

So what i am thinking
During the start of the program i will initialize my module GPRS, as it will take time to properly function

After sending this command
AT+CIPSTART="TCP","Server IP","PORT"

I will get connected to Server,
will it remain forever means if der is no power, will it continue or not

I am thinking that i have to just send AT+CIPSEND Command only, no more than that.
Is it true
or i have to repeat all this process again and gain
Thu Feb 07 2013, 12:48 am
#9
Regarding buffer overrun error, its clear that you are not reading fast enough from rx buffer of UART. by making that change in the code you actually optimized it and so reading happens faster. There is always scope for optimizing code.

Now with TCP stuff. you have to initialize GPRS as well as TCP connection everytime when power cycle the device. and make sure frequency of sending data not more than 15 mins as it may be possible that modem goes into dormancy state.
 07arunsharma like this.
Thu Feb 07 2013, 07:50 am
#10
Thanks
Today i am planning to watch its disassembly listing of this code to see optimjzation.

Now for gprs module
means when i properly initialized gprs module and then i can just use atcipsend command to send data to a server for many days
without re initialization of gprs module.
I have to send 30bytes of data every hour.
Is it okay

what is dormant state.
My module hangd some tim

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

ztaletpzca
Wed Apr 24 2024, 11:19 pm
IrardlPex
Wed Apr 24 2024, 08:42 pm
Charlestehed
Wed Apr 24 2024, 05:20 pm
Robertgurse
Wed Apr 24 2024, 02:43 pm
Richardedils
Wed Apr 24 2024, 04:07 am
Malcolmaccek
Wed Apr 24 2024, 01:21 am
ChrisLub
Tue Apr 23 2024, 05:21 pm
Davidbab
Tue Apr 23 2024, 10:41 am