Skip to main content
Bharath Kumar
Associate
April 20, 2017
Question

STM32L Interrupt not firing. SOS!!

  • April 20, 2017
  • 2 replies
  • 866 views
Posted on April 20, 2017 at 16:04

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.

  1. Unable to set breakpoints inside the 

    void EXTI0_IRQHandler(void) routine. IAR does not accept.

  2. 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);

}

    This topic has been closed for replies.

    2 replies

    Tesla DeLorean
    Guru
    April 20, 2017
    Posted on April 20, 2017 at 17:39

    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.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    Alex R
    Associate II
    April 20, 2017
    Posted on April 20, 2017 at 18:29

    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