2013-03-30 07:09 AM
Hello,
i used a STM32F4Discovery. My code is at the end of this text. The programm should release a interrupt by rising edge on PortD Pin0. Then the LED toggle on PortD Pin14. This does not work. Where is the mistake? Thank you. int main (void) { SystemInit(); GPIO_InitTypeDef GPIO_InitStructure; EXTI_InitTypeDef EXTI_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; GPIO_InitStructure.GPIO_OType = GPIO_OType_OD; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOD, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOD, &GPIO_InitStructure); SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOD, EXTI_PinSource0); 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); NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F; NVIC_Init(&NVIC_InitStructure); while(1) { } } void EXTI0_IRQHandler(void){ if(GPIO_ReadOutputDataBit(GPIOD, GPIO_Pin_14)){ GPIO_WriteBit(GPIOD, GPIO_Pin_14, RESET); }else{ GPIO_WriteBit(GPIOD, GPIO_Pin_14, SET); } EXTI_ClearITPendingBit(EXTI_Line0); }2013-03-30 08:00 AM
In the CMSIS model SystemInit() is called prior to main(), not a good plan to call it again.
EXTI is on the SYSCFG unit, you must enable it's clock. /* Enable SYSCFG clock */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE); Also you should check/clear the interrupt source on entry, so as not to cause the handler to re-enter via a tail-chaining hazard.2013-04-01 04:48 AM
Thank you