AnsweredAssumed Answered

STM32F0Discovery External Interrupt Configuration

Question asked by alca1628 on Jul 11, 2016
Latest reply on Jul 11, 2016 by alca1628
Hi,
I've been trying to get going with this dev. board, but I ran into problems with the external interrupt. No matter what I choose in     SYSCFG->EXTICR[0], the PA0 interrupt is always the selected one. Can anyone of you see what am I doing wrong? The code compiles and the interrupt on PA0 works fine, just that I cannot choose anything else!

/* EXTERNAL INTERRUPTS TEST */
/* Board STM32F0Discovery   */
/* Trigger interrupt on Pin 0, PORTA and toggle the LED */
/* Select Pin 0, PORTB and check no interrupt will be triggered then */

#include "stm32f0xx.h"
void delay (int a); // Function Prototype

int EXTI0Flag = 0;
int ledStatus = 0x0100;
int main(void)
{
      /* GPIOC GPIOA Periph clock enable */
        RCC->AHBENR |= RCC_AHBENR_GPIOAEN;
        RCC->AHBENR |= RCC_AHBENR_GPIOBEN;
        RCC->AHBENR |= RCC_AHBENR_GPIOCEN;

        GPIOA->MODER &= ~(GPIO_MODER_MODER0);
        GPIOB->MODER &= ~(GPIO_MODER_MODER0);
        GPIOC->MODER |= (GPIO_MODER_MODER8_0);

        GPIOC->OTYPER &= ~(GPIO_OTYPER_OT_8);
        // Ensure push pull mode selected for output pins--default

        GPIOA->OSPEEDR |= (GPIO_OSPEEDER_OSPEEDR0);
        GPIOB->OSPEEDR |= (GPIO_OSPEEDER_OSPEEDR0);
        GPIOC->OSPEEDR |= (GPIO_OSPEEDER_OSPEEDR8);
        //Ensure maximum speed setting (even though it is unnecessary)

        GPIOA->PUPDR &= ~(GPIO_PUPDR_PUPDR0);
        GPIOB->PUPDR &= ~(GPIO_PUPDR_PUPDR0);
        GPIOC->PUPDR &= ~(GPIO_PUPDR_PUPDR8);
        //Ensure all pull up pull down resistors are disabled PA0 is connected to external pulldown on STM32F0Discovery baord

    SYSCFG->EXTICR[0]  = 0x0001; //0x0000 for PA0 and 0x0001 for PB0
    //1. clear bits 3:0 in the SYSCFG_EXTICR1 reg to amp EXTI Line to NVIC for PA0
    //   clear bits 3:1 in the SYSCFG_EXTICR1 reg to amp EXTI line to NVIC for PB0

          EXTI->RTSR = EXTI_RTSR_TR0;
    // 2.Set interrupt trigger to rising edge

    EXTI->IMR = EXTI_IMR_MR0; // 3. unmask EXTI0 line
    NVIC_SetPriority(EXTI0_1_IRQn, 1); //4. Set Priority to 1
    NVIC_EnableIRQ(EXTI0_1_IRQn);  // 5. Enable EXTI0_1 interrupt in NVIC (do 4 first)
    while(1)
    {
        if(EXTI0Flag)
        {
            EXTI0Flag = 0;
            GPIOC -> ODR ^= ledStatus; // Toggle the LED if you get here
        }
    }
}

void EXTI0_1_IRQHandler(void)
{
    if( (EXTI->IMR & EXTI_IMR_MR0) && (EXTI->PR & EXTI_PR_PR0))
        {
         EXTI0Flag = 1;
         delay(50000);
         while(GPIOA->IDR & GPIO_IDR_0){} // Wait for the button
         EXTI->PR |= EXTI_PR_PR0 ; // Clear the flag
        }
}

void delay (int a)
{
    volatile int i,j;

    for (i=0 ; i < a ; i++)
    {
        j++;
    }

    return;
}

Outcomes