2016-01-19 02:54 PM
On stm32f072xb (Discovery board), I am able to detect an interrupt on PA0.
Using the example provided, I configured the external interrupt as such.
EXTI->IMR = 0x0001; /* (3) */
EXTI->RTSR = 0x0001; /* (4) */ EXTI->FTSR = 0x0001; /* (5) */I enabled the interrupt
/* Enable and set Button EXTI Interrupt to the lowest priority */
HAL_NVIC_SetPriority((IRQn_Type)(EXTI0_1_IRQn), 0x03, 0x00); HAL_NVIC_EnableIRQ((IRQn_Type)(EXTI0_1_IRQn));My IRQHandler function looks like this
void EXTI0_1_IRQHandler(void)
{ BSP_LED_Toggle(LED_ORANGE);if ((EXTI->PR & 0x0001) != 0) /* Check line 0 has triggered the IT */
{ EXTI->PR |= 0x0001; /* Clear the pending bit */ BSP_LED_Toggle(LED_GREEN); /* Toggle green led on PC9 */ } else /* Should never occur */ { BSP_LED_Toggle(LED_ORANGE); /* Switch on orange led to report an error */ } }I enabled all the peripheral clocks
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE); RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE);When I connect a 5V supply to PA0, I can see the ORANGE and GREEN leds light up.
I am not clear why the example works. I don't see how the code knows that the interrupt is connected to PA0 and not PB0 or PC0. Let's ignore that for now.
*******
I am unable to detect an interrupt on a different pin of my choice.
I configured pin PB12 with Mode GPIO_MODE_IT_RISING_FALLING and GPIO_NOPULL
I modified the example to make it work for PB12EXTI->IMR = 0x1000; /* I am thinking that this should point to pin 12 */
EXTI->RTSR = 0x1000; EXTI->FTSR = 0x1000;I enabled the interrupts and am using the same IRQHandler but after connecting 5V to PB12 pin, no LED lights up.
/* Enable and set Button EXTI Interrupt to the lowest priority */
HAL_NVIC_SetPriority((IRQn_Type)(EXTI4_15_IRQn), 0x03, 0x00); HAL_NVIC_EnableIRQ((IRQn_Type)(EXTI4_15_IRQn));I then tried to use a different IRQHandler, but still no leds light up
void EXTI4_15_IRQHandler(void)
{ BSP_LED_Toggle(LED_ORANGE);if ((EXTI->PR & 0x0001) != 0) /* Check line 0 has triggered the IT */
{ EXTI->PR |= 0x0001; /* Clear the pending bit */ BSP_LED_Toggle(LED_GREEN); /* Toggle green led on PC9 */ } else /* Should never occur */ { BSP_LED_Toggle(LED_ORANGE); /* Switch on orange led to report an error */ } }Hope you can shed some light on this.
Thanks
#exti2016-01-19 03:29 PM
/* Enable SYSCFG clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);/**
* @brief Configure PA0 in interrupt mode
* @param None
* @retval None
*/
static void EXTI_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_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
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_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
/* Enable and set EXTI0 Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = EXTI0_1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPriority = 0x00;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}