2017-04-20 07:04 AM
I'm new to STM32 line of Microcontrollers, However I have worked extensively on TI MSP430 line.
I recently bought STM32L-DISCOVERY with STM32L152RCT6 controller onboard.
I got the en.stsw-stm32077 standard peripherals and CSIR from STM website.
I'm using IAR-EWARM Toolchain with a linker supplied from STM32 Website.
My problems with the following code are as follows.
void EXTI0_IRQHandler(void) routine. IAR does not accept.
The code when put in run mode should actually toggle the LED when interrupted by a falling edge on PA0 which it doesn't. Is there something wrong with the below code.The LED works when put in while mode, so its mostly related to the Interrupt not firing.
Could some one identify the problem?
#include 'stm32l1xx.h'
#include 'Pinouts.h'
#include 'Settings.h'#include 'functions.h'#include 'LIB_WSN.h'
#include 'LIB_CC1101.h'#include 'Variables.h'
char buffer, addr;
EXTI_InitTypeDef EXTI_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;NVIC_InitTypeDef NVIC_InitStructure;void EXTI0_Config(void);
int main()
{ //WiNode.Init(); //WiNode.Init_CLK(); WiNode.Init_LED(); /* Configure PA0 in interrupt mode */ EXTI0_Config(); /* Generate software interrupt: simulate a falling edge applied on EXTI0 line */ //EXTI_GenerateSWInterrupt(EXTI_Line0); while(1) {}
}void EXTI0_Config(void){ /* Enable GPIOA clock */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); /* Configure PA0 pin as input floating */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; GPIO_Init(GPIOA, &GPIO_InitStructure);/* Enable SYSCFG clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);/* Connect EXTI0 Line to PA0 pin */
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource0);/* Configure EXTI0 line */
EXTI_InitStructure.EXTI_Line = EXTI_Line0; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; 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 = 0x00; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x00; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure);}/* Set interrupt handlers *//* Handle PA0 interrupt */void EXTI0_IRQHandler(void) { if (EXTI_GetITStatus(EXTI_Line0) != RESET) { GPIO_SetBits(LED_GPIO, LEDON_PIN); delay_ms(1000); GPIO_ResetBits(LED_GPIO, LEDON_PIN); EXTI_ClearITPendingBit(EXTI_Line0); }EXTI_ClearFlag(EXTI_Line0) ;
EXTI_ClearITPendingBit(EXTI_Line0);}
2017-04-20 08:39 AM
Not being able to set breakpoints suggest the code isn't bound into the final image.
If using a .cpp file or C++ then you'd want to use
extern 'C' void EXTI0_IRQHandler(void) {
...
}
Make sure the vector table names match, and that the linker binds it. Check .MAP for names, check binary for physical addresses.
2017-04-20 09:29 AM
Hi,
The instruction:
delay_ms(1000);
should not be in an interrupt handler.
It would be better to set a flag in the IRQ handler, and then check for the flag status in the main() function.
Is your startup code (interrupt vector table) calling the right handler?
Regards,
Alex