cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F0Discovery External Interrupt Configuration

lab
Associate II
Posted on July 11, 2016 at 09:15

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 */

&sharpinclude ''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;

}

#syscfg-exti
5 REPLIES 5
Posted on July 11, 2016 at 11:09

Perhaps you'd want to enable the SYSCFG clock?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
lab
Associate II
Posted on July 11, 2016 at 11:47

Hi,

Thank you for you response, really. I have been trying to figure this

out for a few days now, but I don't think I follow though,

Do you mean something like this?

RCC->APB2ENR |= RCC_APB2ENR_SYSCFGEN;

I don't have the board in front of me right now, but I'll definitely test with this.

I have the reference manual and the datasheet for the stm32f051R8, but somehow

I think I'm missing some literature. The codes I found so far do not mention anything

about the SYSCFG clock :( , if you could point me to some more literature it would help me a lot.

Best regards,

Walid FTITI_O
Senior II
Posted on July 11, 2016 at 12:29

Hi,

I recommend that you run the ''GPIO_EXTI'' example in the

http://www.st.com/content/st_com/en/products/embedded-software/mcus-embedded-software/stm32-embedded-software/stm32cube-embedded-software/patch-cubefw-f0.html

wich configure the EXTI line 0. Compare the code there with yours.

The example at this path : STM32Cube_FW_F0_V1.5.0\Projects\STM32F072B-Discovery\Examples\GPIO\GPIO_EXTI

-Hannibal-

lab
Associate II
Posted on July 11, 2016 at 13:01

Hi,

Thank you for your reply, I'll definitely will look into the Cube software, it seems interesting. I want however, to get more insight into what I'm doing for the start. This is why I'm avoiding the routines included with CMSIS and trying to write ''from scratch''. Maybe that's not such a good idea, but I'm learning a lot!

Regards,

lab
Associate II
Posted on July 11, 2016 at 13:06

Hi again,

Now I have tested, I added the line:

RCC->APB2ENR |= RCC_APB2ENR_SYSCFGEN;

and everything works now as it should. Thank you very much for your help,

very much appreciated. I missed completely this and the examples I found on the web don't mention this for some reasons.

One more time, thank you very much for your help, now I can continue my trip into learning this amazing chips.

Regards,