2013-01-18 01:20 AM
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--);
}
2013-01-18 01:33 AM
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 .2013-01-18 01:46 AM
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.
2013-01-18 02:27 AM
I think its ok to define an external interrupt handler in the main function...
2013-01-18 03:26 AM
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.
2013-01-18 04:44 AM
2013-01-18 05:30 AM
.h file and corresponding .c file make a library, or is my vocabulary missed?
2013-01-18 06:50 AM
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?2013-01-18 08:04 AM
''.h file and corresponding .c file make a library, or is my vocabulary missed?''
I'm afraid your vocabulary is ''missed'' here.2013-01-23 07:53 AM
Sorry for late reply- I was away. How do you say source and header file together then?