/var/www/restricted/ssh/stm32/www/stm32circle/ STM CircleOS forum / Primer 2 EXTI not working for Joystick's Left,Right,Up & Down pins

Username:     
Password:     
             

Forum
  • Index
  •  » STM32 primer
  •  » Primer 2 EXTI not working for Joystick's Left,Right,Up & Down pins

# 1   2009-06-27 04:42:32 Primer 2 EXTI not working for Joystick's Left,Right,Up & Down pins

satishgn
Member
From: Mumbai, India
Registered: 2009-04-24
Posts: 11

Primer 2 EXTI not working for Joystick's Left,Right,Up & Down pins

Hi,

This is my first post to this forum. I got my new Primer2 last week & I've been trying to test my STM32 standard peripheral API knowledge by running simple task (bypassing CircleOS)

I cannot get the EXTI configuration working for the Joystick Left,Right,Up & Down buttons. (Only exception is the centre button of the joystick which generates interrupt properly. This works)

I wanted to test the EXTI interrupt handlers when any button on the joystick is pressed. In the handler one of the LED is toggled.

Please help.

Thanks,
Satish

Here is the code snippet:

    //LEDs port and pins
    #define GPIO_LED                        GPIOE   
    #define RCC_APB2Periph_GPIO_LEDS        RCC_APB2Periph_GPIOE
    #define GPIO_LED0_PIN                   GPIO_Pin_0
    #define GPIO_LED1_PIN                   GPIO_Pin_1
    #define GPIO_LEDS_BOTH_PINS             (GPIO_LED0_PIN | GPIO_LED1_PIN)

    //Joystick port and pins
    #define GPIO_JSTIK                      GPIOE
    #define RCC_APB2Periph_GPIO_JSTIK       RCC_APB2Periph_GPIOE
    #define GPIO_JSTK_UP_PIN                GPIO_Pin_3
    #define GPIO_JSTK_DOWN_PIN              GPIO_Pin_4
    #define GPIO_JSTK_RIGHT_PIN             GPIO_Pin_5
    #define GPIO_JSTK_LEFT_PIN              GPIO_Pin_6
    #define GPIO_JSTK_ALL_PINS              (GPIO_JSTK_LEFT_PIN | GPIO_JSTK_RIGHT_PIN | GPIO_JSTK_UP_PIN | GPIO_JSTK_DOWN_PIN)

    //Push button port and pin
    #define GPIO_PUSH_BUTTON                GPIOA
    #define RCC_APB2Periph_GPIO_PUSH_BUTTON RCC_APB2Periph_GPIOA
    #define GPIO_PUSH_BUTTON_PIN            GPIO_Pin_8

    //All necessary clocks enabled
    ....
    ....

  // Configure PE.00 and PE.01 as output push-pull
  GPIO_InitStructure.GPIO_Pin = GPIO_LEDS_BOTH_PINS;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIO_LED, &GPIO_InitStructure);
 
  // Configure PE.03 to PE.06 as input
  GPIO_InitStructure.GPIO_Pin = GPIO_JSTK_ALL_PINS;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIO_JSTIK, &GPIO_InitStructure);

  // Configure PA.08 as input
  GPIO_InitStructure.GPIO_Pin = GPIO_PUSH_BUTTON_PIN;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIO_PUSH_BUTTON, &GPIO_InitStructure);


  EXTI_InitTypeDef EXTI_InitStructure;

  GPIO_EXTILineConfig(GPIO_PortSourceGPIOE, GPIO_PinSource3);
  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); 

  GPIO_EXTILineConfig(GPIO_PortSourceGPIOE, GPIO_PinSource4);
  EXTI_InitStructure.EXTI_Line = EXTI_Line4;
  EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
  EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  EXTI_Init(&EXTI_InitStructure); 

  GPIO_EXTILineConfig(GPIO_PortSourceGPIOE, GPIO_PinSource5);
  EXTI_InitStructure.EXTI_Line = EXTI_Line5;
  EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
  EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  EXTI_Init(&EXTI_InitStructure); 

  GPIO_EXTILineConfig(GPIO_PortSourceGPIOE, GPIO_PinSource6);
  EXTI_InitStructure.EXTI_Line = EXTI_Line6;
  EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
  EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  EXTI_Init(&EXTI_InitStructure); 

  GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource8);
  EXTI_InitStructure.EXTI_Line = EXTI_Line8;
  EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
  EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  EXTI_Init(&EXTI_InitStructure); 


  NVIC_InitTypeDef NVIC_InitStructure;
 
  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
 
  NVIC_InitStructure.NVIC_IRQChannel = EXTI3_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);

  NVIC_InitStructure.NVIC_IRQChannel = EXTI4_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);

  NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);

  In stm32f10x_it.c

/******************************************************************************/
/*            STM32F10x Peripherals Interrupt Handlers                        */
/******************************************************************************/

void EXTI3_IRQHandler(void)
{
  if(EXTI_GetITStatus(EXTI_Line3) != RESET)
  {
    //Toggle Led
    GPIO_WriteBit(GPIO_LED, GPIO_LED0_PIN, (BitAction)((1-GPIO_ReadOutputDataBit(GPIO_LED, GPIO_LED0_PIN))));

    EXTI_ClearITPendingBit(EXTI_Line3);
  }
}

void EXTI4_IRQHandler(void)
{
  if(EXTI_GetITStatus(EXTI_Line4) != RESET)
  {
    //Toggle Led
    GPIO_WriteBit(GPIO_LED, GPIO_LED0_PIN, (BitAction)((1-GPIO_ReadOutputDataBit(GPIO_LED, GPIO_LED0_PIN))));

    EXTI_ClearITPendingBit(EXTI_Line4);
  }
}

void EXTI9_5_IRQHandler(void)
{
  if(EXTI_GetITStatus(EXTI_Line5) != RESET)
  {
    //Toggle Led
    GPIO_WriteBit(GPIO_LED, GPIO_LED0_PIN, (BitAction)((1-GPIO_ReadOutputDataBit(GPIO_LED, GPIO_LED0_PIN))));

    EXTI_ClearITPendingBit(EXTI_Line5);
  }

  if(EXTI_GetITStatus(EXTI_Line6) != RESET)
  {
    //Toggle Led
    GPIO_WriteBit(GPIO_LED, GPIO_LED0_PIN, (BitAction)((1-GPIO_ReadOutputDataBit(GPIO_LED, GPIO_LED0_PIN))));

    EXTI_ClearITPendingBit(EXTI_Line6);
  }

  if(EXTI_GetITStatus(EXTI_Line8) != RESET)
  {
    //Toggle Led
    GPIO_WriteBit(GPIO_LED, GPIO_LED0_PIN, (BitAction)((1-GPIO_ReadOutputDataBit(GPIO_LED, GPIO_LED0_PIN))));

    EXTI_ClearITPendingBit(EXTI_Line8);
  }
}

Offline

 

# 2   2009-06-28 03:20:22 Primer 2 EXTI not working for Joystick's Left,Right,Up & Down pins

satishgn
Member
From: Mumbai, India
Registered: 2009-04-24
Posts: 11

Re: Primer 2 EXTI not working for Joystick's Left,Right,Up & Down pins

Whew.. I found the solution for the above problem.
For EXTI to work with GPIOE(Joystick) port, the clock for AFIO should be enabled which I was not doing earlier. After enabling RCC_APB2Periph_AFIO, the interrupts were serviced.
Surprisingly EXTI worked for GPIOA(Pushbutton) port without enabling AFIO clock.
Wonder whether this has been documented anywhere.
Going to get goodnight sleep tonight smile

Offline

 

# 3   2010-03-03 10:12:35 Primer 2 EXTI not working for Joystick's Left,Right,Up & Down pins

thefly
New member
Registered: 2010-01-27
Posts: 8

Re: Primer 2 EXTI not working for Joystick's Left,Right,Up & Down pins

Hello satishgn,

i tried your Primer2BasicTest, it runs well but i can't modify the Push Button definition. I just want to push the button to shut down with modifing your code:

  GPIO_EXTILineConfig(GPIO_PUSH_BUTTON, GPIO_PUSH_BUTTON_PIN);  //  Connect PUSH_BUTTON to shutdown
  EXTI_InitStructure.EXTI_Line = EXTI_Line2;    /* Configure PUSH_BUTTON to generate an interrupt on rising edge */
  EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
  EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  EXTI_Init(&EXTI_InitStructure);

void EXTI2_IRQHandler(void)
{
  if(EXTI_GetITStatus(EXTI_Line2) != RESET)
  {
   
    //Shutdown Primer2
    GPIO_WriteBit(GPIO_SHUTDOWN, GPIO_SHUTDOWN_PIN, SET);
   
    EXTI_ClearITPendingBit(EXTI_Line2);
  }
}

it's not functionable, i also tried with JSTK_UP & DOWN and they do, but LEFT & RIGHT don't, why is that?
Another questions is, how do you choose the EXTI_Line? Is there some certain routine or how do you know the line is not occupied?

Thanks a lot!

Last edited by thefly (2010-03-03 10:19:16)

Offline

 

# 4   2010-03-03 11:01:06 Primer 2 EXTI not working for Joystick's Left,Right,Up & Down pins

thefly
New member
Registered: 2010-01-27
Posts: 8

Re: Primer 2 EXTI not working for Joystick's Left,Right,Up & Down pins

satishgn :

void EXTI9_5_IRQHandler(void)
{
  if(EXTI_GetITStatus(EXTI_Line5) != RESET)
  {
    //Toggle Led
    GPIO_WriteBit(GPIO_LED, GPIO_LED0_PIN, (BitAction)((1-GPIO_ReadOutputDataBit(GPIO_LED, GPIO_LED0_PIN))));

    EXTI_ClearITPendingBit(EXTI_Line5);
  }

  if(EXTI_GetITStatus(EXTI_Line6) != RESET)
  {
    //Toggle Led
    GPIO_WriteBit(GPIO_LED, GPIO_LED0_PIN, (BitAction)((1-GPIO_ReadOutputDataBit(GPIO_LED, GPIO_LED0_PIN))));

    EXTI_ClearITPendingBit(EXTI_Line6);
  }

  if(EXTI_GetITStatus(EXTI_Line8) != RESET)
  {
    //Toggle Led
    GPIO_WriteBit(GPIO_LED, GPIO_LED0_PIN, (BitAction)((1-GPIO_ReadOutputDataBit(GPIO_LED, GPIO_LED0_PIN))));

    EXTI_ClearITPendingBit(EXTI_Line8);
  }
}

I figured out that the PUSH Button is on GPIOA_PIN8, so i'd use the EXTI_line8, but "error: 'EXTI8_IRQn' undeclared (first use in this function)  ". In the ST Firmware library there are only EXTI_IRQChannel 0-4. How did u use the EXTI_Line8?

Offline

 

# 5   2010-03-03 11:09:24 Primer 2 EXTI not working for Joystick's Left,Right,Up & Down pins

thefly
New member
Registered: 2010-01-27
Posts: 8

Re: Primer 2 EXTI not working for Joystick's Left,Right,Up & Down pins

OK i got it, it's about EXTI9_5, i should read more UM0427, thanks anyway!

Offline

 

  • Index
  •  » STM32 primer
  •  » Primer 2 EXTI not working for Joystick's Left,Right,Up & Down pins

Board footer