cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103 External Switch Interrupt Problem

Utkarash Patil
Associate III
Posted on September 21, 2017 at 11:41

My aim is to generate interrupts on various pins of STM32F103 Nucleo-64, for that i used these steps as mentioned bellow ,

In cubeMx firstly i used 5 pins which are connected to switches and configured them as GPIO_EXTIx  also enabled their respective interrupts in NVIC in configuration tab that are External Interrupt 3, External Interrupt 9:5 and External Interrupt 15:10, also for indication i have connected 5 pins to different LEDs and configured them as Pull up and triggered when falling edge 

And then generated code with some changes as per required also for indication in code i have used an variable and assigned values from 1 to 5 to the variable  which get updated on respective interrupt  ,

I have used a switch statement and in that i have described 5 cases 

But when i am pressing any switch or activating any Interrupt   the first switch case is executed and then the respective case is executed so even if i want the case 5 to executed (Pressing switch 5) it is getting executed but before that case 1 is also getting executed so this is disturbing by functionality 

so i have attached my code below please check with it and help in this concern if i am wrong any where

BELOW ATTACHED BOTH THE FILES HAVE SAME CODE ONE IS IN NOTEPAD AND ANOTHER IS IN .C EXTENSION

4 REPLIES 4
Posted on September 21, 2017 at 14:15

Hello!

>>>' but before that case 1 is also getting executed so this is disturbing by functionality '

Check  your compiler optimisations to be -O0 (no optimisation).

if-else statements forbids to execute  more than one case.

Posted on September 22, 2017 at 05:25

Thank You for your Reply,

I am new to STM so i would request you to please if you can elaborate the step by step procedure of the above mentioned comment,

Also i have updated the code which includes Switch case statement instead of if else statement, But still i am getting same issue 

Please check with the snippet in which i have made changes,

\\*********************\\

void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)

{

uint16_t ui16PinNumber;

ui16PinNumber = GPIO_Pin;

switch(ui16PinNumber)

{

case GPIO_PIN_9:

      ui16Value=1;

      HAL_GPIO_WritePin(GPIOB, GPIO_PIN_8, GPIO_PIN_RESET);

     HAL_Delay(500);

      

break;

case GPIO_PIN_5:

         ui16Value=2;

         HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, GPIO_PIN_RESET);

         HAL_Delay(500);

          break;

case GPIO_PIN_3:

         ui16Value=3;

         HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_RESET);

         HAL_Delay(500);

break;

case GPIO_PIN_12:

         ui16Value=4;

         HAL_GPIO_WritePin(GPIOC, GPIO_PIN_11, GPIO_PIN_RESET);

         HAL_Delay(500);

break;

case GPIO_PIN_10:

      ui16Value=5;

      HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, GPIO_PIN_RESET);

      HAL_Delay(500);

break;

default:

}

}

Posted on September 22, 2017 at 09:46

But still i am getting same issue

Is this mean that PB8 LED from case 1 blinks also?

Posted on September 22, 2017 at 09:50

Yes for every condition it blinks