cancel
Showing results for 
Search instead for 
Did you mean: 

Redundant Interrupt Generation

bsd040
Associate II
Posted on November 24, 2008 at 07:39

Redundant Interrupt Generation

3 REPLIES 3
bsd040
Associate II
Posted on May 17, 2011 at 12:53

Hello,

I write firmware for STM32F10x microcontroller.

I use IAR evaluation board and Workbench for developing and debugging.

Problem Description:

--

I tried to use one of the evaluation board buttons as a source for external interrupt.

I used EXTI example as a reference for writing the code.

Press on the button really causes corresponding interrupt generation.

The only problem is that I get an interrupt right after I enable it in NVIC module (I don't press on the button at this time)

My code:

int main()

{

u32 i,j;

GPIO_TypeDef* GPIOx;

u8 bitVal;

#ifdef DEBUG

debug();

#endif

/* System clocks configuration */

RCC_Configuration();

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);

RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);

NVIC_Configuration();

GPIO_Configuration();

EXTI_Configuration();

while(1)

{

}

}

where

void GPIO_Configuration(void)

{

GPIO_InitStruct->GPIO_Pin = GPIO_Pin_4;

GPIO_InitStruct->GPIO_Speed = 0;

GPIO_InitStruct->GPIO_Mode = GPIO_Mode_IN_FLOATING;

GPIO_Init(GPIOC, &GPIO_InitStruct); // Port C bit 4

}

void NVIC_Configuration(void)

{NVIC_InitTypeDef NVIC_InitStructure;

#ifdef VECT_TAB_RAM

/* Set the Vector Table base location at 0x20000000 */

NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);

#else /* VECT_TAB_FLASH */

/* Set the Vector Table base location at 0x08000000 */

NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);

#endif

NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);

/* Enable the EXTI4_IRQChannel */

NVIC_InitStructure.NVIC_IRQChannel = EXTI4_IRQChannel;

NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

NVIC_Init(&NVIC_InitStructure);

NVIC_ClearIRQChannelPendingBit(EXTI4_IRQChannel);

}

void EXTI_Configuration(void)

{

EXTI_InitTypeDef EXTI_InitStruct;

GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource4); // Port C Bit 4

EXTI_InitStruct.EXTI_Line = EXTI_Line4;

EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt;

EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Rising;

EXTI_InitStruct.EXTI_LineCmd = ENABLE;

EXTI_Init(&EXTI_InitStruct);

EXTI_ClearITPendingBit(EXTI_Line4);

}

How can I prevent the redundant interrupt generation?

Please help.

Regards,

Svetlana

[ This message was edited by: bsd040 on 23-11-2008 09:47 ]

bsd040
Associate II
Posted on May 17, 2011 at 12:53

Thank you very much.

It helped!!! :D

brianforde9
Associate II
Posted on May 17, 2011 at 12:53

Svetlana,

I'm using GPIOs as keypad, without problems. My code is very similar to yours, but the order of init is slightly different. Try the following order (I have not checked this code for correctness...);

I think the problem in your code is that the NVIC is initialised before the EXTI pending interrupt is cleared. In most cases, it would be good practice to configure the NVIC after the corresponding peripheral has been correctly configured and is ready for operation. Not a hard and fast rule, but a reasonable guideline.

Code:

/* enable the clocks... */

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,

ENABLE);

/* floating input */

lsGPIO_InitStruct.GPIO_Pin = GPIO_Pin_4;

lsGPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;

lsGPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;

GPIO_Init(GPIOC,

&lsGPIO_InitStruct);

/* columns as EXTIs */

GPIO_EXTILineConfig(GPIO_PortSourceGPIOC,

GPIO_PinSource4);

EXTI_ClearITPendingBit(EXTI_Line4);

/* EXTI on both edges */

lsEXTI_InitStruct.EXTI_Line = EXTI_Line4;

lsEXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt;

lsEXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Rising_Falling;

lsEXTI_InitStruct.EXTI_LineCmd = ENABLE;

EXTI_Init(&lsEXTI_InitStruct);

/* enable EXTI interrupt */

lsNVIC_InitStruct.NVIC_IRQChannel = EXTI4_IRQChannel;

lsNVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 0;

lsNVIC_InitStruct.NVIC_IRQChannelSubPriority = 0;

lsNVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;

NVIC_Init(&lsNVIC_InitStruct);

Brian F.