RCIF is not activated even if message was receive

Thread Starter

bhodz

Joined Jan 29, 2013
18
hello everyone, im new in pic programming and i want to resolve my problem with the UART.. Im trying to display a message coming from gsm modem to LCD through 877A.. everytime i sent a message to the gsm modem the RCIF is not activated...
hers my code:


#include <pic.h>
#include <stdio.h>
#include "uart.h"
#include "delay.h"
#include "lcd.h"

//Configuration bits
__CONFIG(HS & WDTDIS & LVPDIS & UNPROTECT);




void main()
{


char rcv_data;
char rcv_data_buffer[16];


TRISD7 = 0; //RD7 initialized as output

RD7 = 1; //RD7 is ON..trigger the gsm.
DelayMs(250);
DelayMs(250);
RD7 = 0;
DelayMs(250); /**** delay****/
DelayMs(250); /***wait for the gsm***/
DelayMs(250); /****to be in normal****/
DelayMs(250); /********m

lcd_init(); //Initialize the LCD.
DelayMs(250);
DelayMs(250);
UARTInit(); //Initialize the UART modul
DelayMs(250);


while(1)
{

if(OERR)
{
CREN = 0;
CREN = 1;

}



if(RCIF == 1)
{
rcv_data = (RCREG);

DelayMs(250);
sprintf(rcv_data_buffer,"%c",rcv_data);
DelayMs(250);
lcd_clear();
DelayMs(250);
lcd_puts(rcv_data_buffer);
DelayMs(250);
lcd_puts("God is good");
}
else

{
DelayMs(250);
lcd_clear();
DelayMs(250);
lcd_puts("Jeremiah 29:11");
DelayMs(250);
}
}


}

heres my code under uart init

void UARTInit(void)
{
BRGH = 1; //high-speed
// SPBRG = 25; //9600 baud/s at 4 mhz
SPBRG = 129; //9600 baud/s at 20 mhz
// SPBRG = SPBRG_VAL;

TX9 = 0; //8-bit data
RX9 = 0;

SYNC = 0; //set UART in asynchronouse mode
SPEN = 1; //enable serial port
CREN = 1; //enable continuous receive mode
// RCIE = 1; //enable Rx interrupt
// TXIE = 0; //enable Tx interrupt
TXEN = 1; //enable Transmit
// PEIE = 1; //enable peripheral interrupt
// GIE = 1;
}


tnx in advance.. hope you could help me.. God bless
 

Thread Starter

bhodz

Joined Jan 29, 2013
18
yes,,ive tried sending sms from the gsm and its working..txn for the reply i really appreciate it.. but my problem now is on to read data from UART RCREG., does it have somethinf to do with the message storage? cuz everytime i will send a message to the gsm, it doesn't shows any indication that the message was receive.. but if i disconnect the simcard from it and insert it to a mobile phone, the message was already receive by the simcard...help!! This is our final project as a graduating students and i really had a hard time getting what i want..:( tnx in advance
 

Thread Starter

bhodz

Joined Jan 29, 2013
18
yes i already tried it..i got some improvement..RCIF is now activated everytime it receives a message..my problem now is if i send a "B" charcter, it will display a blank, or null..:(,,hope you could help me..tnx a lot..God bless.

heres my code now..

while(1)
{

if(OERR)
{
CREN = 0;
CREN = 1;

}
if(RCIF == 1)
{
int i=0;
rcv_data = (RCREG);
rcv_data_buffer[i++] = rcv_data;
DelayMs(250);
sprintf(rcv_data_buffer,"%c",rcv_data);
DelayMs(250);
lcd_clear();
DelayMs(250);
lcd_puts(rcv_data_buffer);
DelayMs(250);
lcd_goto(0x40);
DelayMs(250);
lcd_puts("God is good");
}
else

{
DelayMs(250);
lcd_clear();
DelayMs(250);
lcd_puts("Jeremiah 29:11");
DelayMs(250);
}
}
 

Thread Starter

bhodz

Joined Jan 29, 2013
18
i used hitech lite version..,i tried also 9.70, i have a question in mind,, because if i send a message to the gsm, it will idicate that RCIF is set then i dont get any data from rcreg but if i will transfer the simcard to a mobile phone, the message is received already but unread..any idea on this?
 

t06afre

Joined May 11, 2009
5,934
Since you use the hi-tech C compiler in lite mode anyway. I would suggest upgrading to to version 9.83. As start I would have used say Hyper Term or any other terminal program. Just send a byte at the time, and mirror it to a 8 bit wide port. Does your LCD writing work as it should?
 

thatoneguy

Joined Feb 19, 2009
6,359
It does this even if you change your code to "loop back" anything that is entered into the serial port, back to Hyperterm on the PC?

Or does this happen with only the modem?
 

Thread Starter

bhodz

Joined Jan 29, 2013
18
thatoneguy,,im sorry but i dont understand what you mean :(

ive got some changes in my codes and rcv_data=rcreg;
i send an AT command to the gsm then
if i display the rcv_data to the lcd it only displays the "A" then then after a blink it is replced with "T".. i dont why i cant receive the "OK" response of the gsm..
 

Thread Starter

bhodz

Joined Jan 29, 2013
18
thatoneguy,,im sorry but i dont understand what you mean :(

ive got some changes in my codes and rcv_data=rcreg;
i send an AT command to the gsm then
if i display the rcv_data to the lcd it only displays the "A" then then after a blink it is replced with "T".. i dont why i cant receive the "OK" response of the gsm..
 

thatoneguy

Joined Feb 19, 2009
6,359
It sounds like you are pulling characters from the buffer before it is full.

You should read until \n or \r (depending on what it sends), or a NUL before calling it the string received.
 

Thread Starter

bhodz

Joined Jan 29, 2013
18
how would i implement it?,, ive got some observation,,if i send an AT COMMAND like this UARTPuts("AT+CMGS=\"+639194125982\"\r\n");
DelayMs(250);
UARTPuts(rcv_data);
UARTPutch(0x1A)


my phone receive +639194125982"
what has happened? why is it that the comman i send is in the RCREG?(rcv_data=RCREG)
 

thatoneguy

Joined Feb 19, 2009
6,359
If you connect the UART in of the GSM Modem using a TTL<-> USB Serial adapter, you'll be able to see what characters it sends, it may be echoing what is being received on the input so the user can verify the command was sent without errors.
 

Thread Starter

bhodz

Joined Jan 29, 2013
18
If you connect the UART in of the GSM Modem using a TTL<-> USB Serial adapter, you'll be able to see what characters it sends, it may be echoing what is being received on the input so the user can verify the command was sent without errors.

but i already disable the echo..by ATE0\r

is there a possibility that the PIC is the one which is not ok?
 

thatoneguy

Joined Feb 19, 2009
6,359
Best way to try would be to talk to the modem with TTL Serial using your PC and see if it works, and how it responds. It may still echo if you didn't save the setting. Without a Signal analyzer or Bus Pirate or similar, we have NO Clue what is being sent and received.

From what you've done so far, the PIC seems to be talking to the PC Ok. See how the PIC Responds if you respond like the modem when you see the commands on Hyperterm.
 

Thread Starter

bhodz

Joined Jan 29, 2013
18
Best way to try would be to talk to the modem with TTL Serial using your PC and see if it works, and how it responds. It may still echo if you didn't save the setting. Without a Signal analyzer or Bus Pirate or similar, we have NO Clue what is being sent and received.

i already tried this,,the modem is okay, it responds well,


From what you've done so far, the PIC seems to be talking to the PC Ok. See how the PIC Responds if you respond like the modem when you see the commands on Hyperterm.
how to test the PIC with pc?


im confused with my pic,,everytime it receives a txtmsg..in sets RCIF but the contain of the rcreg is just the same as before even if the message is not the same..

part of my command is

AT+CNMI=1,2,0,0,0

the first blink of the lcd (data from rcreg) if it rcvs a txtmsg is 0,0,0
then the second blink is 2,0,0,0................
i dont know why this is always the contain of the rcreg :(

is there a way to clear rcreg or it's automatic cleared?
pls help..
 

thatoneguy

Joined Feb 19, 2009
6,359
When the PIC is Sending, say ATZ, in hyperterminal, type "Ok" and see how the PIC responds.

Use the log from when you tested the modem to see what commands to send to the PIC, essentially, copy what you received from the modem when sending commands and then past those into Hyperterminal and Send to PIC after receiving a command.

Does that make sense?
 

Thread Starter

bhodz

Joined Jan 29, 2013
18
ive got another observation,, i uses a simulator and if found out the working of the program that i made, it really works as with the actual, The problem i experienced before is the one which i observed in simulation, leads me to concusion that its not the hardware but the program thats mess up,, my code is this,,

TRISD7 = 0; //RD7 initialized as output

RD7 = 1; //RD7 is ON..trigger the gsm.
DelayMs(250);
DelayMs(250);
RD7 = 0;
DelayMs(250); /****5 seconds delay****/
DelayMs(250); /***wait for the gsm***/
DelayMs(250); /****to be in normal****/
DelayMs(250); /********mode**********/
DelayMs(250);
DelayMs(250);
lcd_init(); //Initialize the LCD.
DelayMs(250);
DelayMs(250);
UARTInit(); //Initialize the UART modul
DelayMs(250);

UARTPuts("AT\r");
DelayMs(250);
UARTPuts("ATE0\r");
DelayMs(250);
UARTPuts("AT+CMGF=1\r");
DelayMs(250);
UARTPuts("AT+CMGD=1,4\r");
DelayMs(250);
UARTPuts("AT+CNMI=1,2,0,0,0\r");
DelayMs(250);
DelayMs(250);

while(1)
{

if(OERR)
{
CREN = 0;
CREN = 1;

}
if(RCIF == 1)
{
int i=0;
rcv_data = (RCREG);
//rcv_data_buffer = rcv_data;
//i++;rcv_data_buffer=0;
DelayMs(250);
sprintf(rcv_data_buffer,"%c",rcv_data);
DelayMs(250);
lcd_clear();
DelayMs(250);
lcd_puts(rcv_data_buffer);
DelayMs(250);
lcd_goto(0x40);
DelayMs(250);
lcd_puts("God is good");
}
else

{
DelayMs(250);
lcd_clear();
DelayMs(250);
lcd_puts("Jeremiah 29:11");
DelayMs(250);
}
}

}

in my simulation, if i send a character A to the GSM the rcv_data=RCREG equals to A, and it displays correctly in the LCD..but if try to send ABC, the lcd only displays B and it blinks 3times..upon observing it shows that it blinks according to the number of character it rcvs, and if the characters are more than 1, it only reads the 2nd character and blinks it repeatedly according to how many characters it rcvs,, any idea why this is happening? help pls:(
 
Top