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.

while() problem in ccs 6.1.1.00022

Hi, 

Recently, I used CCS 6.1.1.00022 for F28377S launchPad. I found a problem in while() instruction. The program can't jump out the loop of while(). The codes are as following,

Read_Flag=1;
while(Read_Flag==1);

interrupt void spiRxFifoIsr(void)
{

Read_Data=SpiaRegs.SPIRXBUF; // Read data
Read_Flag=0;
PieCtrlRegs.PIEACK.all|=0x20; // Issue PIE ack

}

I have added Read_Flag into Watch Expression and see the Read_Flag is already change to 0. But the program still can't jump out this while(Read_Flag==1);. The program is stop in here. BTW, The program is correct if the code is change as follows.

Read_Flag=1;
while(1){
     if(Read_Flag==0)
         break;
};

But I still would like to know what reason cause the while(Read_Flag==1); can't jump out. I appreciate if you can tell me how to resolve this problem.

Thanks.

Regards,

John

 

  • Hi John,

    It is due to the C compiler and optimizer. They both will analyse your C source code and translate to assembly. Different optimisation level have different register optimisation method. To prevent this issue, you can declare Read_Flag as volatile by using "volatile int Read_Flag;" It will make the allocated register to be updated from memory every time before comparing with 1.