This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

If in SCI FIFO interrupt not having any effect

Hi Folks

I have a piece of code that uses the SCI FIFOs on the F2827PT.

It includes a ISR for the transmit interrupt. Inside this ISR I check a global Uint16 variable for 0 or 1 with an if statement

However whether I check (myVar !=0) or (myVar==1) the statements with in th eif statement are ALWAYS executed.

I have tried:

if (myVar != 0) {

//do something

}

have also tried:

if (myVar == 0) {

//do something

}

have also tried:

if (myVar != 0) {

//do nothing

} else {

//do something

}

and also:

if (myVar == 0) {

//do nothing

} else {

//do something

}

Whatever I do the control ALWAYS reaches the "//do something"... Is there some gotcha for checking vars with if's in ISRs that im missing??

Ta

  • Ive found that if I write code:

    if (myVar = 0) {

    //do one thing

    } else {

    //do another thing

    }

    both things are done, as if the if statement isnt even there...

    Trying with a for statement like the below works OK, but its messy...

    for(; myVar != 0; mVar = 0) {

    //do something once if myVar != 0

    }

    Very strange...

  • Toby,

    Have you tried setting a breakpoint inside of the ISR to check the value of the variable?

    Regards,
    Daniel 

  • Hi

    Yes, I have tried this, I have the variable I am testing added to the watch window, also I have a variable that checks how the if condition evaluates that shows that it should evaluate correctly

    that is

    int check = (myVar !=0) // should evaluate to true if myVar != 0, and does so and vice versa

    if (myVar !=0) { //should also evaluate to true only if  myVar !=0, but it doesnt

    // instructions here get executed when they shouldnt

    } else {

    // instructions here ALSO get executed

    }

    I have tried setting the variable myVar as volatile, but with no effect... :(

  • Toby,

    What if you use the "check" variable in the IF statement?

    Regards,
    Daniel

  • Hi Daniel

    I did also try something like that:

    int foo = 0;

    if (foo != 0) {

      // these shouldnt be executed, but they are

    } else {

      // these are ALSO executeed

    }

    Its as if the control isnt even seeing the if and else and just executing the statements inside the if else as if they were just placed sequentially in the code out side of any conditional logic.

    I did try to see if I cold tell what was happening by looking at the code in the disassembler window, but assembly is not a strong point of mine, especially compiled instead of logically written assembly

    Thanks

  • Did you also try

    if (foo)
    ...
    else
    ...

  • yep.

    I should have a few more ISRs operational tomorrow and can check and see if an If works in them or not or if it is just this specific ISR

  • Have tried if statements in other interrupts and they work fine! the ectual code I am trying to run is shown below

    interrupt void sciaTxFifoIsr(void) {
    Uint16 i;
    if (sciFifoSetupTxInt != 0) {
    for (i = 0; i < sciFifoTxBufSize; i++) {
    SciaRegs.SCITXBUF = sciFifoTxBuf[i];
    }
    }
    PieCtrlRegs.PIEACK.bit.ACK9 = 1; // Acknowledge CPU interrupt
    }
  • What does sciFifoSetupTxInt indicate and how is it set?

    Also, don't forget to clear your Interrupt flag.

  • Whoops should have mentioned that.

    sciFifoSetupTxInt is a Uint16 declared and intialised to zero globally in that file.

    It is used as a flag to prevent the Interrupt from doing anything when the SCI interrupts are first enabled and the Tx FIFO is naturally empty, but not because its finished sending something.

    So the SCI FIFO Tx function sets this flag so that when the Tx interrupt does run it will do something.

    Im probably going to try and redesign this particular flag away, but I cant imagine I wont still need to use if s in the Tx ISR.

  • What kind of system are you running that would need to continously TX data?

    For me, I would configure the TX FIFO interrupt to trigger on a NON-zero FIFO level, indicating I wrote data that needs to be sent.

  • Hi

    The system doesn't continuously send data, but this way the Tx interrupt occurs when data has BEEN sent, thus allowing the ISR to fill up the FIFO again if there is data longer than 4 words needing to be sent.

  • Wow its suddenly working!?!

    The only thing I can think of having done differently is the contents of the if have changed i.e. the instructions between if(){ and }else{ have changed

    Hmm, thats rather strange.

    Thanks anyway Daniel.

  • Toby Mole said:

    The system doesn't continuously send data, but this way the Tx interrupt occurs when data has BEEN sent, thus allowing the ISR to fill up the FIFO again if there is data longer than 4 words needing to be sent.

    The code you posted above, as written, will dump all of the data from sciFifoTxBuf[] in to the TX FIFO anytime the TX FIFO is empty, unless you have sciFifoSetupTxInt set to 0.  (I assume that you have a separate piece of code that fills sciFifoTxBuf[] and sets sciFifoSetupTxInt)

    The problem here is that unless you disable the interrupt using the registers, your TX FIFO ISR will CONSTANTLY run when you have no data to send, even if only to do nothing.  This will prevent any kind of background task from running.

    If you are concerned about overloading the TX FIFO, what I would do is configure the TX FIFO ISR to trigger on a FIFO level of 3 or 4.  Once you are in the TX FIFO ISR, have it loop doing nothing until the FIFO level drops to 1 or 0.  Then clear the interrupt flags and exit the ISR.  Using this method, all you have to do is write the data to the SCI without worrying about splitting it up into chunks (which is the point of having a FIFO).