cancel
Showing results for 
Search instead for 
Did you mean: 

Code alters a variable on itself

HBesi.1
Associate II

Hello,

I want to be able to do multiple routines in my stm32 code. I went for the option to use Switch case statements. The problem is after the code has done one iteration the variable that is used in the switch statement(routine_test) changes on its own. My code is in the attachment.

Best regards

5 REPLIES 5

routine_test changed from 0 to 1?

JW

TDK
Guru

Variables don't change on their own, look for another explanation. You have "routine_test = 1;" within HAL_GPIO_EXTI_Callback, is that what you're talking about?

If you feel a post has answered your question, please click "Accept as Solution".
HBesi.1
Associate II

I wanted when I press the button to start the routine which sets routine_test to 1. and it should stay like that forever. I only change the variable from 0 to 1 in that one function. But when I execute the code it changes back to 0.

TDK
Guru

You can set up a hardware watchpoint on the memory address used by that variable to figure out what is changing it. Probably your DMA buffers are writing out of bounds, since the variable is directly after them.

/* USER CODE BEGIN PV */
//ADC Buffers
uint16_t adc1_val[FULLBUFFERSIZE];
uint16_t adc2_val[FULLBUFFERSIZE];
uint16_t adc3_val[FULLBUFFERSIZE];
 
// lock flags
uint8_t button_locked = 0;

If you feel a post has answered your question, please click "Accept as Solution".
WHort.1
Associate

Are there anywhere minimal examples showing how to handle multiple routines starting with an switch statement in main?