Rx interrupt flag PIC16F628A

Discussion in 'Embedded Systems and Microcontrollers' started by odm4286, Mar 28, 2016.

  1. odm4286

    Thread Starter Active Member

    Sep 20, 2009
    155
    5
    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 (Text):
    1. Rx interrupt
    2.       buffer = RCREG;                                      // Program abruptly leaves ISR if there is only one byte in the buffer
    3.       parse byte using bitwise operators and if statements
    4.       use result of ifs to set certain variables true or false
    5.       while(RCREG);                                        //  empty buffer and clear RCIF
     
    Last edited: Mar 28, 2016
  2. Papabravo

    Expert

    Feb 24, 2006
    10,157
    1,795
    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.
     
  3. odm4286

    Thread Starter Active Member

    Sep 20, 2009
    155
    5
    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!
     
  4. Papabravo

    Expert

    Feb 24, 2006
    10,157
    1,795
    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.
     
  5. Picbuster

    Member

    Dec 2, 2013
    376
    50
    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;
     
  6. odm4286

    Thread Starter Active Member

    Sep 20, 2009
    155
    5
    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".
     
  7. odm4286

    Thread Starter Active Member

    Sep 20, 2009
    155
    5
    Thanks picbuster
     
  8. Papabravo

    Expert

    Feb 24, 2006
    10,157
    1,795
    Grown man? Try acting the part, instead of responding like a spoiled child.
     
Loading...