cancel
Showing results for 
Search instead for 
Did you mean: 

STM32l152 External interrupts problem

k_
Associate II
Posted on August 12, 2013 at 15:29

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:

&sharpinclude ''stm32l1xx_conf.h''

&sharpinclude ''stm32l1xx.h''

&sharpinclude ''stm32l1xx_gpio.h''

&sharpinclude ''stm32l1xx_usart.h''

&sharpinclude ''misc.h''

&sharpinclude ''stm32l1xx_exti.h''

volatile uint32_t dly;

volatile uint32_t dly2;

typedef int RS323_dataIN;

typedef int RS232_dataOUT;

&sharpdefine enableInterrupts() __set_PRIMASK(0);

&sharpdefine 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();

}

#ask-smarter-questions #ffs #understand-your-tools #stm32l152-interrupt-exti
8 REPLIES 8
Posted on August 12, 2013 at 15:56

This probably has undesirable side-effects

RCC->AHBENR = RCC_AHBLPENR_GPIOALPEN;

Think carefully about what you're doing.

Have you break-pointed the interrupt, or just don't see the LED?
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
k_
Associate II
Posted on August 12, 2013 at 16:04

Tried both didn't work, even after removing the line :(

I did most of the code according to pre-loaded firmware on discovery kit. 

Posted on August 12, 2013 at 18:03

// STM32L-Discovery BLUE/GREEN LED Toggle from USER Button - sourcer32@gmail.com
#include ''stm32l1xx.h''
int main(void)
{
EXTI_InitTypeDef EXTI_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
/* Enable GPIOA and GPIOB clock */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOB, 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 = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* Configure PB6 (BLUE LED) and PB7 (GREEN LED) */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIOB->ODR &= ~GPIO_Pin_7;
GPIOB->ODR |= GPIO_Pin_6;
/* Infinite loop */
while(1);
}
void EXTI0_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line0) != RESET)
{
/* Clear the EXTI line 0 pending bit */
EXTI_ClearITPendingBit(EXTI_Line0);
GPIOB->ODR ^= GPIO_Pin_6 | GPIO_Pin_7; // Toggle
}
}

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
k_
Associate II
Posted on August 13, 2013 at 08:20

The problem was in line: 

EXTI_StructInit(&EXTI_InitStruct);

Which was incorrect, and should be like this:

EXTI_Init(&EXTI_InitStruct);

Thank you for your help :)

bmanojredd
Associate
Posted on November 19, 2013 at 08:16

can not open source input file stm32l1xx  error

Posted on November 19, 2013 at 10:47

can not open source input file stm32l1xx error

Sounds like a problem with how you are creating your project, and how the tool chain knows where to find the include files from the firmware library.

Try to formulate a question that conveys some level of detail about what and how you are doing this?
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
bmanojredd
Associate
Posted on December 05, 2013 at 07:53

it is asking stm32l1xx_gpio,exti header files pls send me the header files  ......... 

Posted on December 05, 2013 at 13:13

it is asking stm32l1xx_gpio,exti header files pls send me the header files  .........

 

Wouldn't these ALL be in the firmware library? Review also the project template for your tool chain, as with ST's model these should be pulled in via stm32f1lxx_conf.h

http://www.st.com/web/en/catalog/tools/PF257913

http://www.st.com/web/en/catalog/tools/PF257908

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..