false condition if statement getting executed inside ISR
I’m trying to code an STM32F303 on the STMEVAL-ESC001V1 board
I added the following ISR as user code in the code generated my STM32CubeMX on System Workbench for STM32.
-----------------------------------------
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
// Prevent unused argument(s) compilation warning
UNUSED(GPIO_Pin);
// NOTE: This function Should not be modified, when the callback is needed,
//the HAL_GPIO_EXTI_Callback could be implemented in the user file
PRX_PinState = HAL_GPIO_ReadPin(PRX_GPIO_Port,PRX_Pin);
if(PRX_PinState==GPIO_PIN_SET)
{
FInstance = GETVAL();
tON = FInstance - RInstance;
}
if(PRX_PinState==GPIO_PIN_RESET)
{
RInstance = GETVAL();
tOFF = RInstance - FInstance;
}
}
uint32_t GETVAL(void){
return __HAL_TIM_GET_COUNTER(&htim2);
}
-----------------------------------------
I intend to record the timer value during a rising edge and falling edge on the PRX Pin.
I’m probing the pin and I’m using STMStudio to monitor the global variables.
I’m able to verify the rise and fall reflected on PRX_PinState variable.
It is switching between 1 and 0 as expected.
Which means the If conditions must alternate between true and false.
But when the PRX_PinState switch between 1 and 0, both FInstance and RInstance are refreshed with new values( which are very close number) This means both the if statements are being entered into and executed.
I’m so puzzled i don’t know why.
I’ve tried moving the code and performing it outside the ISR. Everything works fine (not really)
Well, I’m pretty confident that there is problem in the “if” statement’s execution.
But I can’t imagine why.
I also tried using else. (was like that initially)
-----------------------------------------
if(PRX_PinState==GPIO_PIN_SET)
{
FInstance = GETVAL();
tON = FInstance - RInstance;
}
else
{
RInstance = GETVAL();
tOFF = RInstance - FInstance;
}
-----------------------------------------
FInstance = GETVAL(); and RInstance = GETVAL(); are executed immediately one after the other.
How ?
I cannot move further in my project without using a “condition” (to check whether rising or falling).
Please help me.