2016-07-11 12:15 AM
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-exti2016-07-11 02:09 AM
Perhaps you'd want to enable the SYSCFG clock?
2016-07-11 02:47 AM
2016-07-11 03:29 AM
Hi,
I recommend that you run the ''GPIO_EXTI'' example in the 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-2016-07-11 04:01 AM
2016-07-11 04:06 AM
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,