• Resolved

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...

  • In reply to TobyM:

    Toby,

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

    Regards,
    Daniel 

  • In reply to Daniel Chang:

    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... :(

  • In reply to TobyM:

    Toby,

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

    Regards,
    Daniel

  • In reply to Daniel Chang:

    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

  • In reply to TobyM:

    Did you also try

    if (foo)
    ...
    else
    ...

  • In reply to Daniel Chang:

    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

  • In reply to TobyM:

    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
    }
  • In reply to TobyM:

    What does sciFifoSetupTxInt indicate and how is it set?

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

  • In reply to Daniel Chang:

    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.