AnsweredAssumed Answered

Changing EXTI lines

Question asked by lesa on Jan 18, 2014
Latest reply on Jan 19, 2014 by lesa
Hello, first I am sorry if I didn't need to open new thread. I searched through lot of examples in this forum, about EXTI. And most of them were similar to my problem, but non of them helped. :(<br>I am using STM32F103C and EXTI example from projects as base. I want to have external interrupt on pin A1. So I changed GPIO_Pin_1, EXTI_Line1 and EXTI1_IRQn. Here is my code:

main_template.c
01.int main(void)
02.{
03.  GPIO_InitTypeDef  GPIO_InitStructure;
04.  EXTI_InitTypeDef EXTI_InitStructure;
05.  NVIC_InitTypeDef NVIC_InitStructure;
06.   
07.  /* Enable the GPIO_LED Clock */
08.  RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOC, ENABLE );
09.  /* Enable the BUTTON Clock */
10.  RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE );
11. 
12.  /* Configure the GPIO_LED pin */
13.  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
14.   
15.  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
16.  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
17.  GPIO_Init( GPIOC, &GPIO_InitStructure );
18.   
19. 
20.  /* Configure Button pin as input floating */
21.  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
22.  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;
23.  GPIO_Init( GPIOA, &GPIO_InitStructure );
24. 
25. 
26.    /* Connect Button EXTI Line to Button GPIO Pin */
27.    GPIO_EXTILineConfig( GPIO_PortSourceGPIOA, GPIO_PinSource1 );
28. 
29.    /* Configure Button EXTI line */
30.    EXTI_InitStructure.EXTI_Line = EXTI_Line1;
31.    EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
32.    EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; 
33.    EXTI_InitStructure.EXTI_LineCmd = ENABLE;
34.    EXTI_Init(&EXTI_InitStructure);
35. 
36.    /* Enable and set Button EXTI Interrupt to the lowest priority */
37.    NVIC_InitStructure.NVIC_IRQChannel = EXTI1_IRQn;
38.    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;
39.    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;
40.    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
41. 
42.    NVIC_Init(&NVIC_InitStructure);
43. 
44. 
45.  while (1)
46.  {
47. 
48.  }
49.}

stm32f10x_it.c
01.void EXTI1_IRQHandler(void)
02.{
03.  if(EXTI_GetITStatus(EXTI_Line0) != RESET)
04.  {
05.    /* Toggle LED3 */
06.     STM32vldiscovery_LEDToggle(LED3);
07. 
08.    /* Clear the User Button EXTI line pending bit */
09.    EXTI_ClearITPendingBit(EXTI_Line1);
10.  }
11.}

Is there any problem in code that I'm missing all the time or there could be problem in my hardware connection of input signal? My switch is connected between PA1 and 3.3V.

Thanks everyone for help, in advance.
Sasa

Outcomes