AnsweredAssumed Answered

STM32l152 External interrupts problem

Question asked by masaitis.kestutis on Aug 12, 2013
Latest reply on Dec 5, 2013 by Clive One
Hi,

I'm trying to configure external interrupt on Port A Pin 0 and cannot get it working.
Can't find the problem. The IDR register shows input but interrupt doesn't happen.

The code:


#include "stm32l1xx_conf.h"
#include "stm32l1xx.h"
#include "stm32l1xx_gpio.h"
#include "stm32l1xx_usart.h"
#include "misc.h"
#include "stm32l1xx_exti.h"

volatile uint32_t dly;
volatile uint32_t dly2;
typedef int RS323_dataIN;
typedef int RS232_dataOUT;

#define enableInterrupts()   __set_PRIMASK(0);
#define disableInterrupts()  __set_PRIMASK(1);


GPIO_InitTypeDef GPIO_InitStruct;
USART_InitTypeDef USART_InitStructure;
EXTI_InitTypeDef EXTI_InitStruct;
NVIC_InitTypeDef NVIC_InitStruct;

int main(void)
{

//****************************************************
//Enable Clocks
//****************************************************

RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOB | RCC_AHBPeriph_GPIOC| RCC_AHBPeriph_GPIOD| RCC_AHBPeriph_GPIOE| RCC_AHBPeriph_GPIOH, ENABLE);    
RCC->AHBENR = RCC_AHBLPENR_GPIOALPEN;
RCC->APB1ENR = RCC_APB1ENR_USART2EN;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);





//****************************************************
//GPIOB->PIN7 Output LED
//****************************************************
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_7;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_Init(GPIOB, &GPIO_InitStruct);


//****************************************************
//GPIOA->PIN0  Input button
//****************************************************
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_40MHz;
GPIO_Init(GPIOA, &GPIO_InitStruct);

SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource0);


//*****************************************************
// Init EXTI on GPIOA->Pin0
//*****************************************************

EXTI_InitStruct.EXTI_Line = EXTI_Line0;
EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Rising;
EXTI_InitStruct.EXTI_LineCmd = ENABLE;
EXTI_StructInit(&EXTI_InitStruct);

//*****************************************************
//Init NVIC
//*****************************************************
NVIC_InitStruct.NVIC_IRQChannel = EXTI0_IRQn ;
NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 0x0F;
NVIC_InitStruct.NVIC_IRQChannelSubPriority = 0x0F;
NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStruct);



//Enable interupts
enableInterrupts();
//*****************************************************
//Infinite LOOP
//*****************************************************
while(1)
{

}
}


void EXTI0_IRQHandler(void)
{
// Disable general interrupts
disableInterrupts();

//Output high on Port B pin 7
GPIO_SetBits(GPIOB, GPIO_Pin_7);

//Clear interpupt pending bit
EXTI_ClearITPendingBit(EXTI_Line0);

//Enable interupts
enableInterrupts();
}

Outcomes