cancel
Showing results for 
Search instead for 
Did you mean: 

Changing EXTI lines

jednaksasa
Associate
Posted on January 18, 2014 at 20:49

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


int main(void)

{

GPIO_InitTypeDef GPIO_InitStructure;

EXTI_InitTypeDef EXTI_InitStructure;

NVIC_InitTypeDef NVIC_InitStructure;


/* Enable the GPIO_LED Clock */

RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOC, ENABLE );

/* Enable the BUTTON Clock */

RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE );


/* Configure the GPIO_LED pin */

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;


GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_Init( GPIOC, &GPIO_InitStructure );



/* Configure Button pin as input floating */

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;

GPIO_Init( GPIOA, &GPIO_InitStructure );



/* Connect Button EXTI Line to Button GPIO Pin */

GPIO_EXTILineConfig( GPIO_PortSourceGPIOA, GPIO_PinSource1 );


/* Configure Button EXTI line */

EXTI_InitStructure.EXTI_Line = EXTI_Line1;

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

NVIC_InitStructure.NVIC_IRQChannel = EXTI1_IRQn;

NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;

NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;

NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;


NVIC_Init(&NVIC_InitStructure); 



while (1)

{


}

}

stm32f10x_it.c


void EXTI1_IRQHandler(void)

{

if(EXTI_GetITStatus(EXTI_Line0) != RESET)

{

/* Toggle LED3 */

STM32vldiscovery_LEDToggle(LED3);


/* Clear the User Button EXTI line pending bit */

EXTI_ClearITPendingBit(EXTI_Line1);

}

}

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 #stm32f103-exti #stm32 #discovery #exti
2 REPLIES 2
Posted on January 19, 2014 at 00:19

void EXTI1_IRQHandler(void)

{

if(EXTI_GetITStatus(EXTI_Line1) != RESET)

{

/* Clear the User Button EXTI line pending bit */

EXTI_ClearITPendingBit(EXTI_Line1);

/* Toggle LED3 */

STM32vldiscovery_LEDToggle(LED3);

}

}

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
jednaksasa
Associate
Posted on January 19, 2014 at 07:02

Oops, thank you clive. 🙂 It works now just as it should.