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.

error on receiving reply (PIC16f877a) from gsm phone

Status
Not open for further replies.

waxppl

Junior Member level 2
Joined
Aug 4, 2010
Messages
24
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Location
KUALA LUMPUR, MALAYSIA
Activity points
1,552
i was assigned to to build a home automation system, using phone and communication with pic16f877a. I am able to direct the pic to send out message but i really have a trouble to read the response from the phone(gsm modem). For instance, when i direct pic to sent "AT" to the gsm phone, it should reply "ok" but instead it reply"AT" too(i make it to display the result on LCD). i try to make my array to receive more character but after the second character, the LCD display jammed. PLease help me!! i am so out of idea now.
 

ckshivaram

Advanced Member level 5
Joined
Apr 21, 2008
Messages
5,070
Helped
2,149
Reputation
4,304
Reaction score
2,089
Trophy points
1,393
Location
villingen (Germany) / Bangalore
Activity points
30,086
Does your modem work with terminal properly.... instead of modem, connect controller board to terminal and see what happens when commands work.. check the response...
I think your echo is ON....
 

waxppl

Junior Member level 2
Joined
Aug 4, 2010
Messages
24
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Location
KUALA LUMPUR, MALAYSIA
Activity points
1,552
wat do u mean about terminal? u mean i should straight away connect my pic and gsm phone(modem) to hyperterminal? more explaination please. thanksssss

---------- Post added at 06:17 ---------- Previous post was at 06:14 ----------

i tried to connect my circuit to hyperterminal, it showed my command there but still the phone still wont reply

---------- Post added at 06:20 ---------- Previous post was at 06:17 ----------

i am ablr to ask the gsm phone to send a sms to another phone too, the only problem is, the reply from the phone is corrupted (which show identified character in lCD)
 

ckshivaram

Advanced Member level 5
Joined
Apr 21, 2008
Messages
5,070
Helped
2,149
Reputation
4,304
Reaction score
2,089
Trophy points
1,393
Location
villingen (Germany) / Bangalore
Activity points
30,086
yes i mean hyperterminal when i said terminal.... usually when we develop programs for GSM we connect the controller board to hyperterminal, and when controller sends "AT" to terminal window we type OK instead of modem, and see if controller sends the next command... like this we type the commands on terminal and test the functionality of the controller.. then we connect GSM modem and give command from terminal and see if modem responds to command.... In this way we test both to confirm that there is no problem.. if even after that problem exists then it would be due to hardware interface problem......

Are you printing response of modem for every command controller is sending... print AT ok, ATE0 OK) on lcd to see which command fails ( if it fails)....

Do you have an ISR routine where you display on LCD.. if yes then that could be a problem... dont print or invoke LCD in ISR routine....
 

waxppl

Junior Member level 2
Joined
Aug 4, 2010
Messages
24
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Location
KUALA LUMPUR, MALAYSIA
Activity points
1,552
you mean i should type ok in hyper terminal instead of waiting it to respond by itself? is it possible to put command in hyperterminal and ask it to perform an output through mirocontoller?

i tried to copy the reply chracter by character to and array and then display it out at LCD but the LCD will give me some bug character or jammed if i display the third outcome from the array

---------- Post added at 07:15 ---------- Previous post was at 07:06 ----------

#include<pic.h>

//===============configuration==============================
__CONFIG (0x3F32);

//===============define IO port=============================
//#define send RC0
//#define receive RC1
//#define error RC2


#define lcd PORTB
#define RS RA0
#define E RA1
#define _XTAL_FREQ 20000000

//==============FUNCTION PTOTOTYPE(led)=========================
void uart_send(unsigned char data);
unsigned char uart_rec(void);
void long_delay(unsigned short i);

//==============FUNCTION PTOTOTYPE=========================
void e_pulse(void);
void delay(unsigned short i);
void send_char(unsigned char data);
void send_config(unsigned char data);
void lcd_goto(unsigned char data);
void lcd_clr(void);
void dis_num(unsigned long data);
void increment(unsigned long data);
void read_adc(void);
void disp_temp(void);
unsigned short read_temp(void);

//====================MAIN================================

void main(void)
{


ADCON1=0b00000110;
TRISB=0b00000000;
PORTB=0;
TRISA=0b000;
PORTA=0;

send_config(0b00000001); //clear display at lcd
send_config(0b00000010); //Lcd Return to home
send_config(0b00000110); //entry mode-cursor increase 1
send_config(0b00001100); //diplay on, cursor off and cursor blink off
send_config(0b00111000); //function set

char uart_data1[]="AT";
char uart_data2[]="AT+CPMS=\"ME\"";
char uart_data3[]="AT+CMGR=1";
char uart_data4[]="AT+CMGS=33";
char uart_data5[]="0001000a81108397789900041546595020697320696E2070726F6772657373212121";
char uart_data6[]="AT+IPR=9600";
char uart_data7[]="AT+CMGF=0";
char uart_error[]="AT+CMGD=1";

unsigned char data[6];
unsigned char dat1[6],dat2[6];
unsigned short i, j;
TRISB = 0;
TRISC6 = 0;
TRISC7 = 1;
PORTB = 0;
PORTC = 0;
SPBRG = 129;
BRGH = 1;
TXEN = 1;
TX9 = 0;
RX9 = 0;
SPEN = 1;
CREN = 1;


while (1){

//DUMMY FOR lcd TO SEE OVERALL PROCESS
lcd_clr();
lcd_goto(0);

send_char('r');
send_char('E');
send_char('a');
send_char('d');
send_char('y');

__delay_ms(1000);

//AT+IPR=9600

for(i=0; i<=10; i++)
{
uart_send(uart_data6);

}

uart_send(13);
__delay_ms(2000);


//AT+CMGF=0

for(i=0; i<=8; i++)
{
uart_send(uart_data7);

}

uart_send(13);
__delay_ms(2000);

//AT+CPMS="ME"
for(i=0; i<=12; i++)
{
uart_send(uart_data2);

}

uart_send(13);
__delay_ms(2000);


//AT

for(i=0; i<=1; i++)
{
uart_send(uart_data1);

}


uart_send(0X0D);
__delay_ms(2000);


lcd_clr();
lcd_goto(0);

CREN=0;
CREN=1;

if(OERR==0)
{ dat2[0]=uart_rec();
send_char(dat2[0]);
__delay_ms(2000);
}
else
send_char('W');
dat2[1]=uart_rec();
send_char(dat2[1]);
__delay_ms(2000);

//TO SEE THE THIRD CHARACATER IS A NEW LINE OR NOT
if (dat1[3]==0X0D)
send_char('Y');



else
send_char('N');

__delay_ms(2000);



//DUMMY FOR lcd TO SEE OVERALL PROCESS
lcd_clr();
lcd_goto(0);
send_char('s');
send_char('e');
send_char('n');
send_char('t');
__delay_ms(2000);

}



}





void uart_send(unsigned char data)
{
while(TXIF==0); //only send the new data after
TXREG=data; //the previous data finish sent
}

unsigned char uart_rec(void) //receive uart value
{
unsigned char rec_data;
while(RCIF==0); //wait for data
rec_data = RCREG;
return rec_data; //return the received data
}
 

ckshivaram

Advanced Member level 5
Joined
Apr 21, 2008
Messages
5,070
Helped
2,149
Reputation
4,304
Reaction score
2,089
Trophy points
1,393
Location
villingen (Germany) / Bangalore
Activity points
30,086
yes, you are correct.. i mean you have to type Ok on the hyperterminal when it prints AT on screen. when you type OK , the controller has to accept the response and print the text AT OK on LCD.... after you send the command you just check if the incoming message has "K" in the response . if you get 'K' then print AT OK on LCD... these AT OK should be stored in an array and printed... so lke that you should have array or pass command followed by OK to lcd upon getting 'K" for every response.....

if your program is correct then you should see OK on LCD ............
 

waxppl

Junior Member level 2
Joined
Aug 4, 2010
Messages
24
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Location
KUALA LUMPUR, MALAYSIA
Activity points
1,552
i understand your problem but whenever the contoller is running along with hyperterminal, i cannot interupt by typing in any command, the hyperterminal just keep on running by itslef

---------- Post added at 07:45 ---------- Previous post was at 07:37 ----------

SORRY, i understand your EXPLAINATION but whenever the contoller is running along with hyperterminal, i cannot interupt by typing in any command, the hyperterminal just keep on running by itslef
 

ckshivaram

Advanced Member level 5
Joined
Apr 21, 2008
Messages
5,070
Helped
2,149
Reputation
4,304
Reaction score
2,089
Trophy points
1,393
Location
villingen (Germany) / Bangalore
Activity points
30,086
check your code... its code problem... you dont wait for any input from outside source but are continuously sending at commands... thats the problem....
I will check your code by end of day and pm to you....
 

waxppl

Junior Member level 2
Joined
Aug 4, 2010
Messages
24
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Location
KUALA LUMPUR, MALAYSIA
Activity points
1,552
this is my full code along with the lcd function:
#include<pic.h>

//===============configuration==============================
__CONFIG (0x3F32);

//===============define IO port=============================
//#define send RC0
//#define receive RC1
//#define error RC2


#define lcd PORTB
#define RS RA0
#define E RA1
#define _XTAL_FREQ 20000000

//==============FUNCTION PTOTOTYPE(led)=========================
void uart_send(unsigned char data);
unsigned char uart_rec(void);
void long_delay(unsigned short i);

//==============FUNCTION PTOTOTYPE=========================
void e_pulse(void);
void delay(unsigned short i);
void send_char(unsigned char data);
void send_config(unsigned char data);
void lcd_goto(unsigned char data);
void lcd_clr(void);
void dis_num(unsigned long data);
void increment(unsigned long data);
void read_adc(void);
void disp_temp(void);
unsigned short read_temp(void);

//====================MAIN================================

void main(void)
{


ADCON1=0b00000110;
TRISB=0b00000000;
PORTB=0;
TRISA=0b000;
PORTA=0;

send_config(0b00000001); //clear display at lcd
send_config(0b00000010); //Lcd Return to home
send_config(0b00000110); //entry mode-cursor increase 1
send_config(0b00001100); //diplay on, cursor off and cursor blink off
send_config(0b00111000); //function set

char uart_data1[]="AT";
char uart_data2[]="AT+CPMS=\"ME\"";
char uart_data3[]="AT+CMGR=1";
char uart_data4[]="AT+CMGS=33";
char uart_data5[]="0001000a81108397789900041546595020697320696E2070726F6772657373212121";
char uart_data6[]="AT+IPR=9600";
char uart_data7[]="AT+CMGF=0";
char uart_error[]="AT+CMGD=1";

unsigned char data[6];
unsigned char dat1[6],dat2[6];
unsigned short i, j;
TRISB = 0;
TRISC6 = 0;
TRISC7 = 1;
PORTB = 0;
PORTC = 0;
SPBRG = 129;
BRGH = 1;
TXEN = 1;
TX9 = 0;
RX9 = 0;
SPEN = 1;
CREN = 1;


while (1){

//DUMMY FOR lcd TO SEE OVERALL PROCESS
lcd_clr();
lcd_goto(0);

send_char('r');
send_char('E');
send_char('a');
send_char('d');
send_char('y');

__delay_ms(1000);

//AT+IPR=9600

for(i=0; i<=10; i++)
{
uart_send(uart_data6);

}

uart_send(13);
__delay_ms(2000);


//AT+CMGF=0

for(i=0; i<=8; i++)
{
uart_send(uart_data7);

}

uart_send(13);
__delay_ms(2000);

//AT+CPMS="ME"
for(i=0; i<=12; i++)
{
uart_send(uart_data2);

}

uart_send(13);
__delay_ms(2000);


//AT

for(i=0; i<=1; i++)
{
uart_send(uart_data1);

}


uart_send(0X0D);
__delay_ms(2000);


lcd_clr();
lcd_goto(0);

CREN=0;
CREN=1;

if(OERR==0)
{ dat2[0]=uart_rec();
send_char(dat2[0]);
__delay_ms(2000);
}
else
send_char('W');
dat2[1]=uart_rec();
send_char(dat2[1]);
__delay_ms(2000);

//TO SEE THE THIRD CHARACATER IS A NEW LINE OR NOT
if (dat1[3]==0X0D)
send_char('Y');



else
send_char('N');

__delay_ms(2000);



//DUMMY FOR lcd TO SEE OVERALL PROCESS
lcd_clr();
lcd_goto(0);
send_char('s');
send_char('e');
send_char('n');
send_char('t');
__delay_ms(2000);

}



}





void uart_send(unsigned char data)
{
while(TXIF==0); //only send the new data after
TXREG=data; //the previous data finish sent
}

unsigned char uart_rec(void) //receive uart value
{
unsigned char rec_data;
while(RCIF==0); //wait for data
rec_data = RCREG;
return rec_data; //return the received data
}




//==================subroutine LCD setting ==========================

void send_config(unsigned char data)
{
RS=0;
lcd=data;
delay(500);
e_pulse();
}

void e_pulse(void)
{
E=1;
delay(500);
E=0;
delay(500);
}

void send_char(unsigned char data)
{
RS=1;
lcd=data;
delay(500);
e_pulse();
}


void lcd_goto(unsigned char data)
{
if(data<16)
{
send_config(0x80+data);
}
else
{
data=data-20;
send_config(0xc0+data);
}
}


void lcd_clr(void)
{
RS=0;
send_config(0x01);
delay(600);
}


void dis_num(unsigned long data)
{
unsigned char hundred_thousand;
unsigned char ten_thousand;
unsigned char thousand;
unsigned char hundred;
unsigned char tenth;

hundred_thousand = data/100000;
data = data % 100000;
ten_thousand = data/10000;
data = data % 10000;
thousand = data / 1000;
data = data % 1000;
hundred = data / 100;
data = data % 100;
tenth = data / 10;
data = data % 10;

if(hundred_thousand>0)
{
send_char(hundred_thousand + 0x30); //0x30 added to become ASCII code
send_char(ten_thousand + 0x30);
send_char(thousand + 0x30);
send_char(hundred + 0x30);
send_char(tenth + 0x30);
send_char(data + 0x30);
}

else if(ten_thousand>0)
{
send_char(ten_thousand + 0x30); //0x30 added to become ASCII code
send_char(thousand + 0x30);
send_char(hundred + 0x30);
send_char(tenth + 0x30);
send_char(data + 0x30);
}
else if(thousand>0)
{
send_char(thousand + 0x30); //0x30 added to become ASCII code
send_char(hundred + 0x30);
send_char(tenth + 0x30);
send_char(data + 0x30);
}
else if(hundred>0)
{
send_char(hundred + 0x30); //0x30 added to become ASCII code
send_char(tenth + 0x30);
send_char(data + 0x30);
}
else if(tenth>0)
{
send_char(tenth + 0x30); //0x30 added to become ASCII code
send_char(data + 0x30);
}
else send_char(data + 0x30); //0x30 added to become ASCII code
}

void increment(unsigned long data)
{
unsigned short j;
for(j=10;j>0;j--)
{ lcd_goto(32);
data=data+1;
dis_num(data);
delay(10000);
}

}
//==================subroutine DELAY==========================
void delay(unsigned short i)
{
for(;i>0;i--);
}

---------- Post added at 09:31 ---------- Previous post was at 08:41 ----------

this is the outcome from LCD for only "AT"

 

ckshivaram

Advanced Member level 5
Joined
Apr 21, 2008
Messages
5,070
Helped
2,149
Reputation
4,304
Reaction score
2,089
Trophy points
1,393
Location
villingen (Germany) / Bangalore
Activity points
30,086
see the sample code i sent and try on the same lines.........

what is this function doing uart_send(13);

You should send 0x0a and 0x0d both which you are not doing.......where is the routine to receive response after you send AT ... i dont find that function call after sending command at all....

---------- Post added at 14:24 ---------- Previous post was at 14:18 ----------

why are you sending the commands infinetely... send it only once and put while(1); instead of while (1)...
 
  • Like
Reactions: waxppl

    waxppl

    Points: 2
    Helpful Answer Positive Rating

waxppl

Junior Member level 2
Joined
Aug 4, 2010
Messages
24
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Location
KUALA LUMPUR, MALAYSIA
Activity points
1,552
based on my tryout, uart_send(13) have the same effect as uart_send(0x0D), can u suggest the routine, actually i am new in this, i try my best from studying other uart based coding to make this code.

---------- Post added at 10:20 ---------- Previous post was at 10:15 ----------

i think 13 is in decimal, 0x0D is in hexcimal
 

ckshivaram

Advanced Member level 5
Joined
Apr 21, 2008
Messages
5,070
Helped
2,149
Reputation
4,304
Reaction score
2,089
Trophy points
1,393
Location
villingen (Germany) / Bangalore
Activity points
30,086
modem responds to either ctrlZ or enter( 0x0a & 0x0d) . you need to send both commands and not only one..........

i say connect controller board to terminal and see what you get.

your read routine is having problem .. modiify the program by looking into my sample program........
 
  • Like
Reactions: waxppl

    waxppl

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top