cancel
Showing results for 
Search instead for 
Did you mean: 

Trouble with EXTI

cozzensbp
Associate II
Posted on March 22, 2013 at 21:24

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)

 

{

 

 

}

 

}

 

6 REPLIES 6
Posted on March 22, 2013 at 22:06

I have a push button hooked up to GPIOA.P0 that pulls it to ground. It is configured as input/pull-down.

Can you diagram that, and how it gets to be high? The library example looks like

void EXTI0_Config(void)
{
/* Enable GPIOA clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
/* Configure PA.00 pin as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Enable AFIO clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
/* Connect EXTI0 Line to PA.00 pin */
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource0);
/* Configure EXTI0 line */
EXTI_InitStructure.EXTI_Line = EXTI_Line0;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; // or Falling if button shorts to ground
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
/* Enable and set EXTI0 Interrupt to the lowest priority */
NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
cozzensbp
Associate II
Posted on March 22, 2013 at 22:16

Thanks for the reply!  Here are some pictures of my simple setup:

http://imgur.com/a/iq35g

The white goes to PC.0, and the striped red/brown wire to ground.  

cozzensbp
Associate II
Posted on March 22, 2013 at 22:22

Actually, that code sample you gave worked perfectly!  Thanks!

Posted on March 22, 2013 at 22:25

Again how does this get to be high?

Don't you need a 10K or 47K or something to the 3V rail on the white wire side of the switch (PC0). That or configure the input with an internal pull up?
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
cozzensbp
Associate II
Posted on March 23, 2013 at 00:13

Honestly, I'm not sure.  That's just how I've been doing pull-down with buttons.  Do I need a resistor?  And one more question, I can't see in the reference manual where it talks about NVIC priority.  So if I want another interrupt, how do I set it to be a higher priority, just make those two values higher?  Thanks.

Posted on March 23, 2013 at 00:43

http://elinux.org/File:EGHS-PullUpDownSwitch.jpg

You could have all interrupts at the same priority, it wouldn't really make much difference unless you want certain ones to preempt (interrupt) others.

The NVIC is part of the ARM Cortex-M3 core, you could review some manuals from ARM's site, or Joseph Yiu's books on the core. ST also has a Programming Manual (not the flash one) which describes the M3/M4 cores.

http://www.st.com/web/en/resource/technical/document/programming_manual/CD00228163.pdf

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..