cancel
Showing results for 
Search instead for 
Did you mean: 

Interrupt with F3-Discovery

martin_stojanovski93
Associate II
Posted on August 22, 2013 at 21:40

Hello guys,

Im new to the ST-Family and i have a question about interrupting with a button.

I wanted to make the button on the board as a hardware interrupt, which would trigger some LED-Blinking.

However doesnt work at all.

 I have read the manual and it says to perform a hardware interupt i must:

1.Configure the mask bits of the 23 interrupt lines(EXTI_IMR)

2. Configure the trigger selection bits of the interrupt lines ( EXTI_RTSR and EXTI_FTSR)

3. Configure the enable and mask bits that control the NVIC IRQ channel mapped to the external interrupt controller(EXTI) so that an interrupt coming from one of the 23 line can be correctly acknowledged.

Here is part of my code:

void button_init()

{

RCC->AHBENR |= BIT18;

GPIOA->OSPEEDR |= (BIT1 | BIT2);

GPIOA->PUPDR |= (BIT1 | BIT2);

}

int flag=0;

int main()

{

SystemCoreClockUpdate();           /* Get Core Clock Frequency   */

  if (SysTick_Config(SystemCoreClock / 1000)) { /* SysTick 1 msec interrupts  */

    while (1);                                  /* Capture error              */

  }

LED_Init();

button_init(); //BUtton on PA0

EXTI->IMR |= BIT1; // Enable not maskable interrupt on BIT1 

 EXTI->RTSR |= BIT1; // Rising Edge

SYSCFG->EXTICR[0] &= ~BIT1; //  0000 for interrupt for PA[0]

  while(1){}

}

void EXTI0_IRQHandler(void)

if(EXTI->PR & 1UL)

{

EXTI->PR |= 1UL; // Clear with Setting to BIT1

LED_On(3);

}  

}

}

However, it doesnt work.

Any help will be appreciated, and thanks in advance.

Cheers

#interrupt-f3-problem-help
3 REPLIES 3
Posted on August 22, 2013 at 22:49

The NVIC configuration looks to be missing.

void EXTI0_Config(void)
{
EXTI_InitTypeDef EXTI_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
/* 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_Rising;
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 = 0x0F;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
martin_stojanovski93
Associate II
Posted on August 22, 2013 at 23:44

Thanks for your answer Clive. 🙂

I implemented this function NVIC_EnableIRQ(0);

which seems to be similar to the first line of the NVIC. 

However i have no clue how to find a function which suits to the other ones.

Even though i think they second and third one dont seem to be important, but im curious what the last one does.

NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

Cheers.

martin_stojanovski93
Associate II
Posted on August 23, 2013 at 02:58

I got it now.

You can check that the External Interrupt 0 on STM32 specific Interrupt Numbers is located on #6.

So instead of NVIC_EnableIRQ(0); i have to write NVIC_EnableIRQ(6);

So my final code looks inside the main

EXTI->IMR |= BIT1; // Enable not maskable interrupt  

 EXTI->RTSR |= BIT1; // Rising Edge

SYSCFG->EXTICR[0] &= ~BIT1; // Edit System Configure->External Interrupt 0000 for interrupt on PA[0]

NVIC_EnableIRQ(6); // Enable Nested Vector interrupt for line 0

where the function that is called when an interrupt occurs looks like this :

void EXTI0_IRQHandler(void)

if(EXTI->PR & 1UL) // On interrupt PR is set

{

EXTI->PR |= 1; // Clear with Setting to BIT1

... Do this and that ...

}

Thanks again for pointing it out, clive.

Cheers