AnsweredAssumed Answered

EXTI Interrupts with STM32VLDISCOVERY

Question asked by Ahmed Talaat on Jan 4, 2014
Latest reply on Oct 30, 2014 by Ahmed Talaat
Hello,
I am using STM32VLDISCOVERY and connected 4 tiny push buttons to Pins PB12, PB13, PB14 and PB15. I am using external pull-up resistors of 100K each (I guess 10K would be much better).

Using the following code, I found out that pressing one button generates interrupt on the corresponding pin as well as others (I put multiple breakpoints in the interrupt handle and watched the behaviour using the debugger).
I suspected something wrong with my buttons circuitry. So, I disconnected my external board that holds the buttons and pull-up resistors, and changed the code to use the internal pull-up resistors in the STM32.
Just touching the PINs with my finger generates interrupts on these PINs. If the interrupt triggering is that sensitive to the 50Hz induced by touching the pin then how should I handle the circuitry around my buttons to ensure a stable operation.
Thank you.

#include "stm32f10x.h"
void GPIO_In_Floating(void);
void Buttons_Config(void);
/**
**===========================================================================
**
**  Abstract: main program
**
**===========================================================================
*/
int main(void)
{
    /* Configure system clock to HSI @ 8MHz in the system_stm32f10x.c */
    /* change all IOs into Analog INP to save power */
    GPIO_In_Floating();
 
    /* Configure EXTI on User push button */
    Buttons_Config();
 
  /* Infinite loop */
  while (1)
  {
      PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI);
  }
}
 
void GPIO_In_Floating(void)
{
    GPIO_InitTypeDef    GPIO_InitStruct;
 
      /* Configure all GPIO as analog to reduce current consumption on non used IOs */
      /* Enable GPIOs clock */
      RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC, ENABLE);
 
      GPIO_InitStruct.GPIO_Pin = GPIO_Pin_All;
      GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;
      GPIO_InitStruct.GPIO_Speed = GPIO_Speed_2MHz;
      GPIO_Init(GPIOB, &GPIO_InitStruct);
      GPIO_Init(GPIOC, &GPIO_InitStruct);
                                                  // Keep the STLink Pins alive.
      GPIO_InitStruct.GPIO_Pin = ~(GPIO_Pin_13 | GPIO_Pin_14);
      GPIO_Init(GPIOA, &GPIO_InitStruct);
 
      /* Disable GPIOs clock */
      RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC, DISABLE);
}
 
void Buttons_Config(void)
{
    NVIC_InitTypeDef    NVIC_InitStructure;
    GPIO_InitTypeDef    GPIO_InitStructure;
    EXTI_InitTypeDef    EXTI_InitStructure;
 
    /* Enable GPIOB clock */
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
    /* Configure PB0-PB3 pin as input floating */
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;   // external pull-up 100K resistor
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
    GPIO_Init(GPIOB, &GPIO_InitStructure);
 
    /* Enable AFIO clock */
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
 
    /* Connect EXTI12-15 Line to PB.12-15 pin */
    GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource12);
    GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource13);
    GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource14);
    GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource15);
 
    /* Configure EXTI12-15 line initially for active low push button detection */
    EXTI_InitStructure.EXTI_Line = EXTI_Line12 | EXTI_Line13 | EXTI_Line14 | EXTI_Line15;
    EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
    EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
    EXTI_InitStructure.EXTI_LineCmd = ENABLE;
    EXTI_Init(&EXTI_InitStructure);
 
    /* Enable and set EXTI0 Interrupt to the lowest priority */
    NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStructure);
}

void EXTI15_10_IRQHandler(void)
{
  if(EXTI_GetITStatus(EXTI_Line12) != RESET)
  {
    /* Clear the  EXTI line 12 pending bit */
    EXTI_ClearITPendingBit(EXTI_Line12);
  }
 
  if(EXTI_GetITStatus(EXTI_Line13) != RESET)
  {
    /* Clear the  EXTI line 13 pending bit */
    EXTI_ClearITPendingBit(EXTI_Line13);
  }
 
  if(EXTI_GetITStatus(EXTI_Line14) != RESET)
  {
    /* Clear the  EXTI line 14 pending bit */
    EXTI_ClearITPendingBit(EXTI_Line14);
  }
 
  if(EXTI_GetITStatus(EXTI_Line15) != RESET)
  {
    /* Clear the  EXTI line 15 pending bit */
    EXTI_ClearITPendingBit(EXTI_Line15);
  }
}

Outcomes