Skip to main content
epalaima
Associate III
January 29, 2017
Question

How to Enable GPIO External Interrupts STM32F30x_StdPeriph_Driver

  • January 29, 2017
  • 2 replies
  • 1653 views
Posted on January 29, 2017 at 09:53

Hi I'm working on a project where I need to enable external GPIO interrupts on the STM32F303 discovery board. I've looked up several examples online, but can't seem to get in to work. I'm using theSTM32F30x_StdPeriph_Driver. I see in several examples that GPIO_MODE_IT_RISING is used as the GPIO pin mode for interrupts, but this is a HAL library thing and not present in the StdPeriph.

I am using EXTI_LINE12 with GPIO PB12 in input pullup mode with trigger on the rising edge, vector isEXTI15_10_IRQn. Please let me know if you see anything I am doing wrong, I am at a loss at this point. Code is included below, thanks!

Function where I instantiate GPIO and interrupt (called in main):

static void GPIO_InputInit(void){
 GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOE, ENABLE);
 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOD, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15 | GPIO_Pin_14;
 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
 //GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
 GPIO_Init(GPIOE, &GPIO_InitStructure);
 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15; //GPIO_Pin_12
 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
 GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;
 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
 GPIO_Init(GPIOD, &GPIO_InitStructure);
EXTI_InitTypeDef EXTI_InitStruct;
 NVIC_InitTypeDef NVIC_InitStruct;
/* Tell system that you will use PB12 for EXTI_Line12 */
 SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOB, EXTI_PinSource12);
/* PB12 is connected to EXTI_Line12 */
 EXTI_InitStruct.EXTI_Line = EXTI_Line12;
 /* Enable interrupt */
 EXTI_InitStruct.EXTI_LineCmd = ENABLE;
 /* Interrupt mode */
 EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt;
 /* Triggers on rising and falling edge */
 EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Rising;
 /* Add to EXTI */
 EXTI_Init(&EXTI_InitStruct);
/* Add IRQ vector to NVIC */
 /* PB12 is connected to EXTI_Line12, which has EXTI15_10_IRQn vector */
 NVIC_InitStruct.NVIC_IRQChannel = EXTI15_10_IRQn;
 /* Set priority */
 NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 0x00;
 /* Set sub priority */
 NVIC_InitStruct.NVIC_IRQChannelSubPriority = 0x01;
 /* Enable interrupt */
 NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
 /* Add to NVIC */
 NVIC_Init(&NVIC_InitStruct);
}�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

Interrupt Function:

void EXTI15_10_IRQHandler(void) {
 interruptCounter++;
 interruptFlag = 1;
 if (EXTI_GetITStatus(EXTI_Line12) != RESET) {
 envStage = 1;
 EXTI_ClearITPendingBit(EXTI_Line12);
 }
}�?�?�?�?�?�?�?�?

#standard-peripheral #gpio #exti #interrupt #stm32f303
This topic has been closed for replies.

2 replies

Nesrine M_O
Associate
January 30, 2017
Posted on January 30, 2017 at 16:24

Hi

Palaima.Emmett

,

Have a look to this example :STM32F30x_DSP_StdPeriph_Lib_V1.2.3\Projects\STM32F30x_StdPeriph_Examples\EXTI\EXTI_Example

this projectshows how to configure external interrupt lines, 3 EXTI lines (EXTI5, EXTI6 and EXTI13) when using the STM32303C-EVALare configured to generate an interrupt on each falling or rising edge.

In the interrupt routine a led connected to a specific GPIO pin is toggled.

In this example:

- EXTI5 is mapped to PD5

- EXTI6 is mapped to PE6

- EXTI13 is mapped to PC13

-Nesrine-

Randy Nelson
Associate III
November 24, 2017
Posted on November 24, 2017 at 18:33

Hello,

Did you get interrupts working? I'm also trying to use the STD Periph lib in Keil but not having much success.

Randy

Tesla DeLorean
Guru
November 24, 2017

Posted on November 24, 2017 at 19:25

 ,

 ,

The code you posted was some odd register level stuff, not the Standard Peripheral Library (SPL)

Here a PB4 example in SPL. Make sure PB4 doesn't have any other connectivity on board that might interfere. Look at my accepted Best Answer:

https://community.st.com/s/feed/0D50X00009XkX90SAF

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..