cancel
Showing results for 
Search instead for 
Did you mean: 

Examples of interrupt implementation on V3.1.0 library and IAR compiler

jschatz
Associate II
Posted on October 20, 2009 at 15:49

Examples of interrupt implementation on V3.1.0 library and IAR compiler

4 REPLIES 4
jrheisey
Associate II
Posted on May 17, 2011 at 13:25

Did you ever find an example?

jschatz
Associate II
Posted on May 17, 2011 at 13:25

Is there an example of how I could implement an interrupt operation from a GPIO pin?

I have not been able to find a clear example on the library system...

[ This message was edited by: jschatz on 30-09-2009 19:21 ]

jschatz
Associate II
Posted on May 17, 2011 at 13:25

I did get a reply from the manufacturer directly. His code example looked like this to apply an interrupt from a button on one of the evaluation boards:

--------------------------------------------------------------------------

GPIO_InitTypeDef GPIO_InitStructure;

EXTI_InitTypeDef EXTI_InitStructure;

NVIC_InitTypeDef NVIC_InitStructure;

/* Enable Button GPIO clock */

RCC_APB2PeriphClockCmd(BUTTON_CLK[Button] | RCC_APB2Periph_AFIO, ENABLE);

/* Configure Button pin as input floating */

GPIO_InitStructure.GPIO_Pin = BUTTON_PIN[Button];

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;

GPIO_Init(BUTTON_PORT[Button], &GPIO_InitStructure);

if (Button_Mode == Mode_EXTI)

{

/* Connect Button EXTI Line to Button GPIO Pin */

GPIO_EXTILineConfig(BUTTON_PORT_SOURCE[Button], BUTTON_PIN_SOURCE[Button]);

/* Configure Button EXTI line */

EXTI_InitStructure.EXTI_Line = BUTTON_EXTI_LINE[Button];

EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;

if(Button != Button_WAKEUP)

{

EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;

}

else

{

EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;

}

EXTI_InitStructure.EXTI_LineCmd = ENABLE;

EXTI_Init(&EXTI_InitStructure);

/* Enable and set Button EXTI Interrupt to the lowest priority */

NVIC_InitStructure.NVIC_IRQChannel = BUTTON_IRQn[Button];

NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;

NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;

NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

NVIC_Init(&NVIC_InitStructure);

--------------------------------------------------------------------------

Take note of a few things-

1. It is important to set up the GPIO as if it were an input.

2. EXTI and NVIC are discussed in two different manuals of the documentation.

3. EXTI is a multiplexor that routes the GPIO to a NVIC interrupt.

4. Add the file ''startup_stm32f10x_hd.s'' for large model STM32 to your project get the vector table of interrupts from the CMSIS library section of the V3.1.0 library.

5. Don't forget to enable the AFIO clocking in the RCC_APB2 register.

--------------------------------------------------------------------------

By the way, I am still having a problem in that I don't understand how to select whether the interrupt is level sensitive or edge-triggered.

Does anybody know?

jschatz
Associate II
Posted on May 17, 2011 at 13:25

Problem solved...

It appears that I was not resetting the interrupts pending bit.

The code here is a good example of setting up the interrupts. They are edge-triggered and you must manage the pending register yourself.