AnsweredAssumed Answered

Trouble with EXTI

Question asked by cozzens.brian on Mar 22, 2013
Latest reply on Mar 23, 2013 by Clive One
Hi, I am having some troubles getting EXTI0 working properly with GPIOA.P0.  At present, the interrupt works, just in the wrong way.  I have a push button hooked up to GPIOA.P0 that pulls it to ground.  It is configured as input/pull-down.  However, I put a breakpoint in the interrupt routine, and it's called if the button is not pressed.  So if I start the program while holding the button down, it runs, and as soon as I let up on the button, it triggers the interrupt.  I would like the interrupt to behave in the opposite manner, that it will trigger when the button is pressed.  I have tried changing between rising/falling edge, but it does the same thing.  Any suggestions?  Thanks.

Here is my code:





#include "stm32f10x.h"
#include "stm32f10x_exti.h"


void EXTI0_IRQHandler(void)
{
     
     if(EXTI_GetITStatus(EXTI_Line0) != RESET)
  {
    // ...
          int i =0;
          i++;
    /* Clear the EXTI line pending bit */
    EXTI_ClearITPendingBit(EXTI_Line0);
  }
}






void GPIO_Configuration(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;
  RCC->APB2ENR |= 0x51FD;     
  //RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOC , ENABLE);      
               
  //configure as pull-down
     GPIOC->CRL = 0x08;
     GPIOC->ODR = 0x0000;


}


void EXTI_Configuration(void)
{
     RCC->APB2ENR |= RCC_APB2ENR_AFIOEN;                     // enable clock for Alternate Function
     GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource0);
     EXTI_ClearITPendingBit(EXTI_Line0);
  EXTI->IMR       |= 0x01;            // unmask interrupt
  EXTI->EMR       |= 0x01 ;           // unmask event
  EXTI->RTSR      &= ~0x01 ;         // set rising edge
  EXTI->FTSR      |= 0x01  ;       // set falling edge


     NVIC->ISER[0] |= (1 << (EXTI0_IRQn & 0x1F));    // enable interrupt EXTI 0
  
}




int main()
{
     GPIO_Configuration();
     EXTI_Configuration();
     while(1)
     {
          
     }
}


Outcomes