cancel
Showing results for 
Search instead for 
Did you mean: 

External interrupt subroutine not being called !!!

kunal5959
Associate II
Posted on January 18, 2013 at 10:20

I am trying to write a simple program to toggle an LED at PORTA.3 on trigger by an external interrupt on PORTB.0..a switch is attached to PORTB.0 for changing the state of Port.

I have done the initialization of interrupt and configured the GPIO port properly but still interrupt routine is not called. I am using the IAR workbench C compiler for flashing the code.What could be the mistake?

/**
******************************************************************************
* @file EXTI/main.c 
* @author MCD Application Team
* @version V3.3.0
* @date 04/16/2010
* @brief Main program body
******************************************************************************
* @copy
*
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
* TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*
* <
h2
><
center
>© COPYRIGHT 2010 STMicroelectronics</
center
></
h2
>
*/ 
#include ''stm32f10x.h''
#include ''stm32f10x_gpio.h''
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
GPIO_InitTypeDef GPIO_InitStructure;
void Delay(__IO uint32_t nCount);
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
void NVIC_Configuration(void);
void GPIO_Configuration(void);
void EXIT_Configuration(void);
int main()
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOA, ENABLE);
GPIO_Configuration();
EXIT_Configuration();
NVIC_Configuration();
//Infinite Loop
GPIO_WriteBit(GPIOB,GPIO_Pin_14,Bit_SET);
SysTick_Config(15000000);
while (1)
{ 
}
} 
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
}
void EXIT_Configuration(void)
{
//SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOG, EXTI_PinSource7);
EXTI_InitTypeDef EXTI_InitStructure;
//*Connect Key1 button EXTI Line to key Button GPIO Pin */
GPIO_EXTILineConfig(GPIO_PortSourceGPIOB,GPIO_PinSource14);
//*Configure Key1 button EXTI Line to generate an Interrupt at falling Edge*/
EXTI_StructInit(&EXTI_InitStructure);
EXTI_InitStructure.EXTI_Line = EXTI_Line14;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
//* Generate softwar Interrrupt: simulöate a falling Edge applied on PA6 EXTI Line */
//// EXTI_Gene´rateSWInterrupt(EXTI_Line0);
}
void NVIC_Configuration(void)
{
////#ifdef VEST_TAB_RAM
// /* Set the vector table location at 0x20000000 */
// NVIC_SetVectorTable(NVIC_VectTAB_RAM,0x0);
//#else /*VEST_TAB_FLASH*/
// /* Set the vector table location at 0x80000000 */
// NVIC_SetVectorTable(NVIC_VectTab_FLASH,0x0);
//#endif
// 
/* Enable External Interrupt*/
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x01;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x01;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
//Finally I have to create the interrupt handler. The EXTI2_IRQHandler handles external interrupts on lines 5 ~ 7. This method is actually defined in my CPUs startup assembly file as a weak reference. I just need to redefine the method and the linker will do the rest.
}
void EXTI15_10_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line14) != RESET)
{
GPIO_WriteBit(GPIOA,GPIO_Pin_4,Bit_SET);
GPIO_WriteBit(GPIOA,GPIO_Pin_4,Bit_RESET);
EXTI_ClearITPendingBit(EXTI_Line14);
} 
}
void Delay(__IO uint32_t nCount)
{
for(; nCount != 0; nCount--);
}

10 REPLIES 10
crt2
Associate II
Posted on January 18, 2013 at 10:33

IRQHandler should probably be in library (.h file) where other Interrupt handlers are set - or you should at least make a call there to your function.

In FWLib you have them in stm32f10x_it.h .
frankmeyer9
Associate II
Posted on January 18, 2013 at 10:46

IRQHandler should probably be in library (.h file) where other Interrupt handlers are set - or you should at least make a call there to your function.

 

Neither is a *.h file a library, nor should one ever put any code there.

kunal5959
Associate II
Posted on January 18, 2013 at 11:27

I think its ok to define an external interrupt handler in the main function... 

frankmeyer9
Associate II
Posted on January 18, 2013 at 12:26

I think its ok to define an external interrupt handler in the main function...

 

Not sure what you mean, but the implied statement is not correct.

You can have both the main function and the interrupt handler in the same module (*.c file),

as long as their names match that expected by the startup file/linker.

But if you have this, the interrupt handler is not ''extern''.

And second, in C you cannot define a function inside of another function. But I guess you did not mean that.

kunal5959
Associate II
Posted on January 18, 2013 at 13:44

Yes you are right ,,the context is completely wrong..I meant IRQ_Handler can be defined in the *.c filewhich also contains the main () function.

crt2
Associate II
Posted on January 18, 2013 at 14:30

.h file and corresponding .c file make a library, or is my vocabulary missed?

Posted on January 18, 2013 at 15:50

So how is GPIOB being configured? You want to configure it as a digital input.

Does the switch ground? It is pulled up/down externally?

You want a rising edge?

Can you breakpoint things, or use a debugger?
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Andrew Neil
Evangelist
Posted on January 18, 2013 at 17:04

''.h file and corresponding .c file make a library, or is my vocabulary missed?''

I'm afraid your vocabulary is ''missed'' here.

crt2
Associate II
Posted on January 23, 2013 at 16:53

Sorry for late reply- I was away. How do you say source and header file together then?