cancel
Showing results for 
Search instead for 
Did you mean: 

Problem in external interrupt on PORTB

Vikas Singh
Associate II
Posted on November 07, 2017 at 06:31

I am using STM32F0308 Dicovery Board. I want to use external interrupt on PIN11 of PORTB. Problem is that I am not able to invoke the PORTB. Microcontroller is still uses PIN11 of PORTA. I know that pins of ports are clubbed together but I am specifying PORTB still micro is using PORTA.

I think there is some problem in this code line

SYSCFG->EXTICR[3] = SYSCFG_EXTICR3_EXTI11_PB;  

Here is code

#include'stm32f0xx.h'

volatile int portBPin10Counter;

void EXTI4_15_IRQHandler(void)

{

  if(EXTI->PR & EXTI_PR_PR11)

  {

     EXTI->PR |= EXTI_PR_PR11;

     portBPin10Counter++;

  }

  }

int main(void)

{

RCC->AHBENR |=RCC_AHBENR_GPIOBEN;

GPIOB->MODER &= ~GPIO_MODER_MODER11;

GPIOB->PUPDR &= ~GPIO_PUPDR_PUPDR11;

SYSCFG->EXTICR[3] =SYSCFG_EXTICR3_EXTI11_PB;

EXTI->RTSR |= EXTI_RTSR_TR11;

EXTI->IMR |= EXTI_IMR_MR11;

NVIC_EnableIRQ(EXTI4_15_IRQn);

NVIC_SetPriority(EXTI4_15_IRQn,1);

    while(1)

    {

    }

}

7 REPLIES 7
Posted on November 09, 2017 at 01:14

Do you have SYSCFG clock enabled in RCC?

JW

Vikas Singh
Associate II
Posted on November 09, 2017 at 05:16

Yes this worked. Thanks. ST have not mentioned about this in code example of reference manual on page no732. Index of array EXTICR is also wrong. Final code is like this

#include'stm32f0xx.h'

volatile int portBPin11Counter;

void EXTI4_15_IRQHandler(void)

{

if((EXTI->PR & EXTI_PR_PR11)&&(EXTI->IMR & EXTI_IMR_MR11))

{

EXTI->PR |= EXTI_PR_PR11;

portBPin11Counter++;

}

}

int main(void)

{

RCC->AHBENR |=RCC_AHBENR_GPIOCEN;

RCC->APB2ENR |=RCC_APB2ENR_SYSCFGEN;

SYSCFG->EXTICR[2] = (uint16_t)SYSCFG_EXTICR3_EXTI11_PC;

EXTI ->FTSR |= EXTI_FTSR_TR11;

EXTI->IMR |= EXTI_IMR_MR11;

NVIC_EnableIRQ(EXTI4_15_IRQn);

NVIC_SetPriority(EXTI4_15_IRQn,0);

while(1)

{

}

}
Posted on November 09, 2017 at 09:29

Index of array EXTICR is also wrong.

Indeed, the numbering from 1 is confusing.

In such cases I tend to write the index as

SYSCFG->EXTICR[3 - 1]

to hint for the future myself that it is a gotcha. Although, in this very particular case I might be also inclined to write

SYSCFG->EXTICR[11 / 4]

and add a comment to explain the '3' in the constant's name.

JW

Pilous Droip
Senior
Posted on November 09, 2017 at 13:15

Hi friend. I try this code on my STM32F407, and I have a problem. I have this code, but interrupt doesn't generate.

My intterupt pin is PD4.

int8_t PD4_init(void)

{

LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOD);

LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_SYSCFG);

SYSCFG->EXTICR[1] = (uint16_t)SYSCFG_EXTICR2_EXTI4_PD;

LL_EXTI_EnableFallingTrig_0_31(EXTI_FTSR_TR4);

LL_EXTI_EnableIT_0_31(EXTI_IMR_MR4);

NVIC_EnableIRQ(EXTI4_IRQn);

NVIC_SetPriority(EXTI4_IRQn,0);

/* output pin with LED*/

LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOD);

LL_GPIO_SetPinMode(GPIOD,LL_GPIO_PIN_14,LL_GPIO_MODE_OUTPUT);

return 0;

}

void EXTI4_IRQHandler (void)

{

if ( LL_EXTI_IsActiveFlag_0_31(EXTI_PR_PR4) && LL_EXTI_IsEnabledIT_0_31(EXTI_IMR_MR4) )

{

LL_EXTI_ClearFlag_0_31(EXTI_PR_PR4);

LL_GPIO_TogglePin(GPIOD,LL_GPIO_PIN_14); //toggle with RED LED

}

}

Any idea, what can be wrong?? Thank you

Posted on November 09, 2017 at 12:24

ST have not mentioned about this in code example of reference manual on page no732.

Indeed. However, those code fragments are meant only as a rough guideline. It's better to use the

http://www.st.com/en/embedded-software/stm32snippetsf0.html

as a starting point, as they form a complete working example.

JW

Posted on November 10, 2017 at 08:32

A lots of thanks for the link. I recently migrated from arduino to ST and this is really helpfull for people like me. But that refrence manual teach me how to code from data sheet. It is lengthy process but I am sure it will help in ling run. Keep up the good work.

Posted on November 10, 2017 at 09:57

Can't see any obvious problem. Verify the input signal is present on pin, e.g. by toggling the LED in a trivial check in a loop in main(), with no interrupts and no other code.

JW