Rx interrupt flag PIC16F628A

Thread Starter

odm4286

Joined Sep 20, 2009
243
As I step through some software I've written in the debugger I've noticed my ISR doesn't run correctly if I only inject 1 byte into RCREG. It seems to "bounce" out of the ISR as soon as I read RCREG. I've experimented by injecting 2 bytes into the register and this fixes the issue. Is this caused by the clearing of RCIF after RCREG is empty? I would think the ISR would at least complete once before returning back to the main program? It isn't a big deal to send two bytes instead of one but it just seems strange the ISR would end so abruptly. Using MPLAB X and XC8

Unfortunately I don't have the actual code with me but here is an example of what I'm trying to do. NOTE TO MODS: THIS IS PSEUDO CODE BELOW

Code:
Rx interrupt
      buffer = RCREG;                                      // Program abruptly leaves ISR if there is only one byte in the buffer
      parse byte using bitwise operators and if statements
      use result of ifs to set certain variables true or false
      while(RCREG);                                        //  empty buffer and clear RCIF
 
Last edited:

Papabravo

Joined Feb 24, 2006
12,702
That is no way to write an interrupt routine. Doing processing of any kind in an interrupt is usually a mistake. The purpose of the interrupt routine is to get the data out of the hardware and into memory for later processing. Of course if you had given us the actual code we might be able to offer more help for a problem which seems to have no basis in reality.
 

Thread Starter

odm4286

Joined Sep 20, 2009
243
Thanks for the reply and the condescending tone ;). I don't have the actual code with me, but I will modify the ISR tonight and deal with the data outside of the ISR. Thanks!
 

Papabravo

Joined Feb 24, 2006
12,702
When you put stuff out on the interwebs you must expect competent viewers to give you their unvarnished opinions. You can then process them anyway you want to. Why would you expect a sugar coated answer? Did you get used to that treatment where you grew up and went to school? If so, that is too bad, because the world is a much harsher place than that.
 

Picbuster

Joined Dec 2, 2013
983
hi,
normal way of handling is

in ISR
// test for under or overrun usart reset when applicable code mcu depending

Input_buffer[n] = Reg;
n++; // update counter
if (n>Buffsize){n=0}; // oops more chars then buffer space
if (Reg== terminator)
{
// stop receive initiate handshake command (hw or xoff/ xon mechanism)
Receive_flag=1;
} //

// end isr

in main
If (Receive_flag)
{
// do what you like to do with received data read max of n chars
.
.
Receive_flag=0; // set receiver ready to it's job Xon or HW
}

// and do in your .h file
# define thru 1
# define false 0
unsigned int n;
unsigned int Buffsize=80;
char Input_buffer[Buffsize]; // care full some compilers will not eat this and you are forced to char Input_buffer[80];

it becomes more readable now
for Receive_flag=1; change to Receive_flag=true;
for Receive_flag=0; change to Receive_flag=false;
 

Thread Starter

odm4286

Joined Sep 20, 2009
243
When you put stuff out on the interwebs you must expect competent viewers to give you their unvarnished opinions. You can then process them anyway you want to. Why would you expect a sugar coated answer? Did you get used to that treatment where you grew up and went to school? If so, that is too bad, because the world is a much harsher place than that.
I'm a grown man, not some kid. I had a question and I asked. I noted in my post I did not have the source with me, if that bothered you so much just ignore my post. No need for "life lessons".
 

Papabravo

Joined Feb 24, 2006
12,702
I'm a grown man, not some kid. I had a question and I asked. I noted in my post I did not have the source with me, if that bothered you so much just ignore my post. No need for "life lessons".
Grown man? Try acting the part, instead of responding like a spoiled child.
 
Top