Skip to main content
haythem
Associate III
March 31, 2014
Question

EXTI interupt problem

  • March 31, 2014
  • 3 replies
  • 711 views
Posted on March 31, 2014 at 02:01

Hi i have a problem with interuption EXTI. I want to execute my principal function with an interuption with EXTI but it dosen't work ! only one instruction does work, this is my code. plz some one help me.

  1. void EXTI_IRconfig(void)
  2. {
  3. NVIC_InitTypeDef   NVIC_InitStructure;
  4.  SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource3);
  5.  
  6.   /* Configure EXTI Line3 */
  7.   EXTI_InitStructure.EXTI_Line = EXTI_Line3;
  8.   EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  9.   EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; 
  10.   EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  11.   EXTI_Init(&EXTI_InitStructure);
  12.  
  13.  NVIC_InitStructure.NVIC_IRQChannel = EXTI3_IRQn;
  14.   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  15.   NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  16.   NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  17.   NVIC_Init(&NVIC_InitStructure);
  18. }

/*******************************************/

#include ''stm32f4xx_it.h''

/*********************************************/

  1. extern capteurIR;
  2. void EXTI3_IRQHandler(void)
  3. {
  4. if(EXTI_GetITStatus(EXTI_Line3) != RESET)
  5.   {
  6. capteurIR=GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_3);
  7. EXTI_ClearITPendingBit(EXTI_Line3);
  8. }
  9. if (GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_3)!=1)
  10. {
  11.  GPIO_ToggleBits(GPIOD, GPIO_Pin_15);
  12. }
  13. else
  14. {
  15. GPIO_ResetBits(GPIOD, GPIO_Pin_15);
  16. }
  17. }
    This topic has been closed for replies.

    3 replies

    Tesla DeLorean
    Guru
    March 31, 2014
    Posted on March 31, 2014 at 03:49

    It would have helped if there more context.

    Make sure you've configured the pins, and that the GPIO and SYSCFG clocks are enabled.

    On a rising edge, you're likely to find the pin high when you enter the service routine.
    Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
    m_fawaz
    Associate
    March 31, 2014
    Posted on April 01, 2014 at 00:45

    Dear Claude,

    I did not get why you are trying to read PA3 in the interrupt handler ''EXTI3_IRQHandler''.

    Knowing that you configured the interrupt to be on the rising edge

    ''EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;'', you will find PA3 to be high as Clive1 stated.

    I will paste a piece of code that compiles and works fine:

    1) replace the method EXTI_IRconfig with the following:

    void EXTILine3_Config(void)

    {

      GPIO_InitTypeDef   GPIO_InitStructure;

      NVIC_InitTypeDef   NVIC_InitStructure;

      /* Enable GPIOA clock */

      RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);

      /* Enable SYSCFG clock */

      RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);

      /* Configure PA3 pin as input floating */

      GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;

      GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;

      GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;

      GPIO_Init(GPIOA, &GPIO_InitStructure);

      /* Connect EXTI Line3 to PA3 pin */

      SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource3);

      /* Configure EXTI Line3 */

      EXTI_InitStructure.EXTI_Line = EXTI_Line3;

      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 EXTI Line3 Interrupt to the lowest priority */

      NVIC_InitStructure.NVIC_IRQChannel = EXTI3_IRQn;

      NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x01;

      NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x01;

      NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

      NVIC_Init(&NVIC_InitStructure);

    }

    2) call the function EXTILine3_Config(); in the ''main'' in order to configure the interrupt.

    3) Provided that you properly configured GPIOD, you can use the code below for the interrupt handler to toggle PD15

    void EXTI3_IRQHandler(void)

    {

      if(EXTI_GetITStatus(EXTI_Line3) != RESET)

      {

        GPIO_ToggleBits(GPIOD, GPIO_Pin_15);

        EXTI_ClearITPendingBit(EXTI_Line3);

      }

    }

    Tesla DeLorean
    Guru
    March 31, 2014
    Posted on April 01, 2014 at 01:04

    I might suggest a slight different instruction sequence to avoid the pipeline hazard with tail-chaining.

    void EXTI3_IRQHandler(void)
    {
    if (EXTI_GetITStatus(EXTI_Line3) != RESET)
    {
    EXTI_ClearITPendingBit(EXTI_Line3); // Do Early, avoid pipeline hazard 
    GPIO_ToggleBits(GPIOD, GPIO_Pin_15);
    }
    }

    There are also F4 examples in the firmware library STM32F4xx_DSP_StdPeriph_Lib_V1.3.0\Project\STM32F4xx_StdPeriph_Examples\EXTI\EXTI_Example\main.c
    Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..