2013-08-22 12:40 PM
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-help2013-08-22 01:49 PM
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);
}
2013-08-22 02:44 PM
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
Cheers.2013-08-22 05:58 PM