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.

EK-TM4C1294XL: I don't know why this works?

Part Number: EK-TM4C1294XL

I have an interrupt set for the PORTP0 line:

void portP_ISR( void)
{
uint32_t ui32Status;


ui32Status = GPIOIntStatus( GPIO_PORTP_BASE, true);

//
// Clear all the pin interrupts that are set
//
GPIOIntClear( GPIO_PORTP_BASE, ui32Status);

rec_dwell = true; /* Set a flag to indicate the packet is done... */
}

In the main code I have:

while ( rec_dwell == false)
{}

The rec_dwell does not seem to register. I know it is seeing the interrupt.

When I change the check to:

while ( rec_dwell == false)
{

  foo( 0, 0);

}

The code functions fine and jumps for the loop.

foo is:

void foo ( unsigned char data, unsigned char address)
{

}

So the question is: Why does this solve this issue?

Byron

  • So the question is: Why does this solve this issue?

    If the rec_dwell variable isn't declared volatile then that would explain the symptoms in that:

    a. With the while ( rec_dwell == false) loop with the empty body the compiler is free to assume rec_dwell is not changed by anything else so an infinite loop may be generated.

    b. When a function call is inserted in the while ( rec_dwell == false) loop body, the function call may change rec_dwell and so the compiler inserts code to check the value of rec_dwell every iteration around the loop.

    I.e. try to declare rec_dwell as:

    volatile bool rec_dwell;

  • This was the answer Chester. Thank you so very much! Another valuable guru and a good bit of information on my side.