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.

For loop in the function stops code execution

Hi,

I have a very strange problem about F28335 programming; when I write a function that only includes for loop like below, code stops at the ADC macro (when i suspend the code with debugger, instruction pointer always stays at there), and does not continue, when I change the content of ADC macro (delete some lines), some changes fix the problem but some changes cause the code stop at Mem Copy functions. These functions is not related with my function, I think that happens randomly (it seems like that).
Even if I do not call that funciton AAA, it still stops my code, definiton of that function is enough. But more strange think is that; when I add some lines to that function, code works with no problem; my examples are below.

Functions that stops the code--------->

void AAA()
{
Uint16 i;

for(i=0; i < 15; i++ );
}

and

void AAA()
{
Uint16 i;

Uint16 a;

for(i=0; i < 15; i++ );
}

Functions that do not stop the code--------->

void AAA() // I added i=0
{
Uint16 i=0;

for(i=0; i < 15; i++ );
}

void AAA() // I added i=0
{
Uint16 i;

i=0;

for(i=0; i < 15; i++ );
}

void AAA() // I added i++
{
Uint16 i;

i++;

for(i=0; i < 15; i++ );
}

void AAA() // I added i++
{
Uint16 i;

for(i=0; i < 15; i++ );

i++;
}

void AAA()// I added a=0
{
Uint16 i;

Uint16 a;

a=0;

for(i=0; i < 15; i++ );
}

void AAA()// I delete i=0 @ for loop
{
Uint16 i;

for(i; i < 15; i++ );
}

void AAA()// I changed Uint16 with Uint32
{
Uint32 i;

for(i=0; i < 15; i++ );
}

I think it means that; using extra RAM space does not fix the problem but using extra code space fixes the problem; could you try it at your own project? I also changed the place of function definiton and function name but the result is same, what can be the reason? (I am using FLASH programming configuration)

Thanks.

  • Hi,

    I'm unsure what you're trying to achieve. I would recommend you to declare these variables globally.

    Regards,

    Gautam

  • I am trying to understand why my code is not working as expected. I have written a function that only inclueds "for loop" and my code starts to not work even if I do not call that function. But adding dummy code line (like i++;) fixes that problem. But this is not complete solution for me, I want to learn the reason of my problem. If I do not know the reason, similar problems may occur later, or maybe I have similar problems but I could only realised that last one. I have written a function for waiting 100ns, that is below, and it causes that problem.

    void Wait_200ns() //I have changed its name as AAA at the previous message.
    {
    Uint16 i;

    for(i=0; i < 15; i++ );
    }

    Why does this function affect other parts of my code? Can it be linker problem?

  • Hi Gökhan;

    The easiest way is examining the assemler output and map files (before AND after).

    It saves a lot of time and is standard practice in similar interpretation-related problems.