Author Topic: STM32F105VB Interrupts  (Read 2805 times)

0 Members and 1 Guest are viewing this topic.

Offline mcdescaTopic starter

  • Contributor
  • Posts: 28
STM32F105VB Interrupts
« on: August 16, 2015, 08:35:14 am »
Dear everybody,

I am currently programing this mcu to react to external interrupts.

There is a button at PORTA9 and a software-driven LED at PORTB12.

When I press the button (with pull-down resistor and debouncing cap), the mcu freezes (if I switch on and off an LED inside the while(1) loop, it will freeze) and no output led is activated.

What do you think? What steps do you recommend me to follow for its debug?

Many thanks.

Code snippet:

Code: [Select]

void EXTI_5_9_Handler(void) {
   EXTI_ClearITPendingBit(EXTI_Line9);
   GPIO_SetBits(GPIOB , GPIO_Pin_12);
}

main() {
   RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB , ENABLE);   
   RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOE , ENABLE);
   RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);

   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
   GPIO_Init(GPIOB, &GPIO_InitStructure);

   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
   GPIO_Init(GPIOA, &GPIO_InitStructure);

   EXTI_ClearITPendingBit(EXTI_Line9);

   //Connect EXTI Line to Button Pin
   GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource9);
   //Configure Button EXTI line
   EXTI_InitStructure.EXTI_Line = EXTI_Line9;
   //select interrupt mode
   EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
   //generate interrupt on rising edge
   EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
   //enable EXTI line
   EXTI_InitStructure.EXTI_LineCmd = ENABLE;
   //send values to registers
   EXTI_Init(&EXTI_InitStructure);
   //configure NVIC
   //select NVIC channel to configure
   NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn;
   //set priority to lowest
   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;
   //set subpriority to lowest
   NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;
   //enable IRQ channel
   NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
   //update NVIC registers
   NVIC_Init(&NVIC_InitStructure);

   while(1) {}

}

« Last Edit: August 16, 2015, 09:07:11 am by mcdesca »
 

Offline andersm

  • Super Contributor
  • ***
  • Posts: 1198
  • Country: fi
Re: STM32F105VB Interrupts
« Reply #1 on: August 16, 2015, 08:52:13 am »
You're clearing the wrong pending bit inside the ISR.

Offline mcdescaTopic starter

  • Contributor
  • Posts: 28
Re: STM32F105VB Interrupts
« Reply #2 on: August 16, 2015, 09:06:38 am »
Corrected, that was wrong from the copy paste, I've tried on another input pin before. It should turn on the LED anyway, but no.

My guess is that the NVIC is looking for the handler in a wrong address...
 

Offline mcdescaTopic starter

  • Contributor
  • Posts: 28
Re: STM32F105VB Interrupts
« Reply #3 on: August 16, 2015, 11:05:19 am »
Ok, excuse me, after looking at the .map file, it was the name of the handler, should be -> void EXTI9_5_IRQHandler(void)

Best,
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

- - -
-->