cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC Creator & Designer Software

SAJO_1338106
Contributor

Since the previous topic titled "ISR build errors"  was closed, I am opening the new thread. DatasheI tried most of the solution on that post but still seeing peculiar behavior of the debugger.

After If (flag == False)After If (flag == False)Before If (flag == False)Before If (flag == False)Suggested in the previous threadSuggested in the previous thread
Following is the code 

From the watch window we could see that the value of flag is false but still it will not go into the if condition.
if(flag == FALSE || flag == false)
{

flag = TRUE;//Message begins

//Valid starting sequences

}
else if(flag && rx_i == rx_len)

flag = FALSE;//message ends


else

rx_i=0;flag=FALSE;//garbage received ignore the message
continue;

}

 

Kindly let me know how to resolve the ISR issue.

0 Likes
1 Solution
ncbs
Moderator
Moderator

Hello @SAJO_1338106,

When a variable is declared as volatile, it indicates that the value of that variable may changed at any time. The compiler is instructed not to optimize the assembler code for the same. There may be situations where the value of our desired variable may be changed by another code/interrupt service routine and in such situations, the "volatile" keyword becomes necessary.

When declared as volatile, the value of the variable is always read from the variable's memory location (since the value could have changed).


When optimization is set, there are situations where the variable might be considered to have no change in its value. To prevent this, optimization is chosen as "none".

 

I also observe that in the question, the code was : 

else
rx_i=0;flag=FALSE;//garbage received ignore the message

But I guess it should have been the following:

else
{
rx_i=0;flag=FALSE;//garbage received ignore the message
}

Anyway, the code has been modified and it seems to have no issues with the braces now.

 

Regards,
Nikhil

View solution in original post

0 Likes
5 Replies
ncbs
Moderator
Moderator

Hello @SAJO_1338106,

1. Try declaring the variable flag as volatile.

2. I suspect that the compiler optimization is NOT set to "none". 
Right-click on the project -> build settings -> expand toolchain in the tree present at the left -> Compiler -> Optimization -> set Optimization level to "none".

 

Regards,
Nikhil

0 Likes
SAJO_1338106
Contributor

Dear Nikhil,

Sorry for the delay in response.

I have made both the changes and modified the code a bit.

 

volatile uint8 flag=FALSE,client_detected=FALSE,live_

if(flag)
{

if(rx_i==rx_len && rx_len>=5 )
{
//Copy only if a valid sequence is received
strcpy(commands[command_cnt++],ch);
// UART_1_ClearRxBuffer();
}
rx_i=0;rx_len=0;flag=FALSE;
}
else
{
flag = TRUE;
continue;
}

 

Still I am having trouble understanding the system at work. Regardless of the optimization, why after executing a statement(a variable) does not change the value or changes to a random value.

Appreciate your assistance.

0 Likes
ncbs
Moderator
Moderator

Hello @SAJO_1338106,

When a variable is declared as volatile, it indicates that the value of that variable may changed at any time. The compiler is instructed not to optimize the assembler code for the same. There may be situations where the value of our desired variable may be changed by another code/interrupt service routine and in such situations, the "volatile" keyword becomes necessary.

When declared as volatile, the value of the variable is always read from the variable's memory location (since the value could have changed).


When optimization is set, there are situations where the variable might be considered to have no change in its value. To prevent this, optimization is chosen as "none".

 

I also observe that in the question, the code was : 

else
rx_i=0;flag=FALSE;//garbage received ignore the message

But I guess it should have been the following:

else
{
rx_i=0;flag=FALSE;//garbage received ignore the message
}

Anyway, the code has been modified and it seems to have no issues with the braces now.

 

Regards,
Nikhil

View solution in original post

0 Likes
SAJO_1338106
Contributor

Dear Nikhil,

Now, I understand that the declaration and optimization settings set to "none" did changed the outcome. Also, I took care of braces in my previous message. 

It working fine now.

0 Likes
ncbs
Moderator
Moderator

Dear @SAJO_1338106,

Glad to hear that your project is working fine now. 😊

Best regards,
Nikhil

0 Likes