RCIF is not activated even if message was receive

thatoneguy

Joined Feb 19, 2009
6,359
It sounds like you are getting just 1 character at a time, then calling it the entire receive buffer, displaying it, and repeating.

Read the code above closely for how it gets data, and compares to yours, also compare with datasheet.

Rich (BB code):
//rcv_data_buffer = rcv_data;
        //i++;rcv_data_buffer=0;


Does it work WITH those lines commented out, or only when they are not?
 

thatoneguy

Joined Feb 19, 2009
6,359
Try putting the UART receive code in an interrupt, then the interrupt return will clear the RCIF flag.

I think what is happening is that you are reading a character, displaying it, but the RCIF flag is not getting cleared (now that it IS activating). It is a read only flag, so the only way to clear it is to read the entire buffer, and/or read through an interrupt (resulting in a return to interrupt because data is in RCREG)

From Microchip Forums:
RCIF is cleared when you read RCREG and there are no more characters in the FIFO. The input shift register is not part of the FIFO. If a character is in the process of shifting into the shift register, RCIF remains clear until the entire character is shifted in, and then that character is transferred to the RCREG FIFO and RCIF is set at that time.
 

Thread Starter

bhodz

Joined Jan 29, 2013
18
Try putting the UART receive code in an interrupt, then the interrupt return will clear the RCIF flag.

I think what is happening is that you are reading a character, displaying it, but the RCIF flag is not getting cleared (now that it IS activating). It is a read only flag, so the only way to clear it is to read the entire buffer, and/or read through an interrupt (resulting in a return to interrupt because data is in RCREG)
maybe you got it right..and i thinks it is really what is happening in the rcreg..im trying to do that kind of routine called FIFO but i couldn't understand and get it right:(
when i try using

void interrupt ISR(void)

i always got" cgpic.exe has stopped working"
what do you think is the problem?
 
Last edited:

thatoneguy

Joined Feb 19, 2009
6,359
I pretty much use BoostC for everything, not sure on the error you are getting.

Maybe something like this?
Rich (BB code):
i=0;
while (RCIF==1)
{
      buffer[i++]=RCREG;
}
See if it gets out of the loop or crashes. :p
 

Thread Starter

bhodz

Joined Jan 29, 2013
18
tnx for the codes,, im still having a problem.

it displays more than 1 character at a time if i send ABC

it will display A, then blink, then display CC..
if i will send AB it will display A then B...

my code

if(RCIF=1)
{
int i=0;
while (RCIF=1)
{
array[i++] = RCREG;
}

lcd_clear();
lcd_puts(array);
DelayMs(250);
DelayMs(250);
DelayMs(250);
DelayMs(250);

}

:( help pls..
 
Last edited:

thatoneguy

Joined Feb 19, 2009
6,359
Try your old code

replace (RCREG) with RCREG

The code above isn't putting a NULL on the end of the string. you could do buffer[sizeof(buffer)+1]='\0'; right efore printing string or similar (that line won't work exactly as shown, but you get the idea)

don't print string until RCIF=0, but if you are waiting for a long stream of characters to come in, you'll be reading them far faster than they can be sent over serial.

I hate delays, but they can be useful for debugging. Send command, delay 1/10th second, then read buffer and see what it shows.
 
Last edited:

thatoneguy

Joined Feb 19, 2009
6,359
First, have you tried the loopback? Where when you send something out to the PIC, whatever it receives comes back?

Before switching designs, get it working. The PIC has a FIFO buffer that will hold several characters if the itnerrupt isn't read immediately.

The hardware serial is the most straightforward and simple to use interface to implement. Trying to create a new and different buffer on top of hardware you cannot get to function currently, the advanced project will not work, either.

I'd suggest trying the serial demo that comes with Sourceboost BoostC Their free version is excellent and has examples. It may be some keyword in your code wrong for the compiler. Just see if you can get a loopback working, and a command/response to the PIC with a serial terminal on a PC. Something like a calculator app.

At that point, you should be fully familiarized with the serial interface, and can then move to working with th emodem. I use BoostC for most everything in the PIC12 to PIC18 series, and the price is beyond reasonable, even for the pro version. Free Restrictions still do optimization, ou are only limited in RAM banks.

The reason I'm asking you to change horses in the middle of the race isn't to abandon your current dev system, but I know the hardware serial demo with BoostC works, so that's a "known good" point that can be compared to the code you are using. Keywords and functions are different, but not so far apart you won't be able to quickly translate between them.
 

Thread Starter

bhodz

Joined Jan 29, 2013
18
thatoneguy tnx a lot,, ive got my problem solved,, my next concern is on how to shift display one char at a time, do you have nay sample codes or idea of its algorithm?
 

thatoneguy

Joined Feb 19, 2009
6,359
For others that have the same issue, could you post how you fixed your problem?

For scrolling text, you'll need to be more specific. There is a built in shift left/shift right with Hitachi based LCD Displays, but it shifts all lines at once. If you want to scroll a single line, it gets more complicated.
 

Thread Starter

bhodz

Joined Jan 29, 2013
18
here is my code that solved my problem::::


void interrupt ISR(void)
{
if(INTE && INTF)
{

Used = Used + 1;

INTF = 0;


}
if(RCIE && RCIF)
{

rcv_data = RCREG;
if (rcv_data=='\r' || rcv_data=='\n')
{
if(rcv_data=='\n')
{
rcvstrindex=0;
}
}
//-----------------------------------------------------------------------------//
/***FOR NOTIFICATIONS***/

else if(rcv_data=='$')
{
rcvstrindex=0;
is_new_message_received_ready1=1;
is_new_message_received='w';
}
//----------------------------------------------------------------------------//
/***FOR MONTHLY BILLINGS***/

else if(rcv_data=='^')
{
rcvstrindex=0;
is_new_message_received_ready2=1;
is_new_message_received='x';
}

//---------------------------------------------------------------------------//
/***FOR INQUIRED BILLING***/
else if(rcv_data=='~')
{
rcvstrindex=0;
is_new_message_received_ready3=1;
is_new_message_received='y';
}
//----------------------------------------------------------------------------//
/***FOR MONTHLY READING***/

else if(rcv_data=='#')
{
rcvstrindex=0;
is_new_message_received_ready4=1;
is_new_message_received='z';
}

//----------------------------------------------------------------------------//
else if(rcv_data=='%')
{
rcvstrindex=0;
is_new_message_received='n';
}
else
{
if(is_new_message_received=='w')
{
rcvbuffer0[rcvstrindex]=rcv_data;
rcvbuffer0[rcvstrindex+1]='\0';
rcvstrindex++;
}
if(is_new_message_received=='x')
{
rcvbuffer1[rcvstrindex]=rcv_data;
rcvbuffer1[rcvstrindex+1]='\0';
rcvstrindex++;
}
if(is_new_message_received=='y')
{
rcvbuffer2[rcvstrindex]=rcv_data;
rcvbuffer2[rcvstrindex+1]='\0';
rcvstrindex++;
}

if(is_new_message_received=='z')
{
rcvbuffer3[rcvstrindex]=rcv_data;
rcvbuffer3[rcvstrindex+1]='\0';
rcvstrindex++;
}

}
}
}
 

thatoneguy

Joined Feb 19, 2009
6,359
Can you format it and put it in code tags so it is a bit more readable?

The code is the octothorpe button on the advanced editor bar. The code looks extremely different. Was the part that made the serial work moving it to an ISR?
 
Top