STM32F103 Programming - 7-Pin Input Function - Button (Interrupt)

Publisher:诗意世界Latest update time:2018-12-11 Source: eefocusKeywords:STM32F103 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Turn on the AFIO clock. External interrupt, remapping, multiplexing function? When configuring the values ​​in the six AFIO registers, you need to turn on the AFIO clock.


void EXTI0_Config(void)


{


  /* Enable GPIOA clock */


  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);


  


  /* Configure PA.00 pin as input floating */


  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;


  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;


  GPIO_Init(GPIOA, &GPIO_InitStructure);


  /* Enable AFIO clock */


  RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);



  /* Connect EXTI0 Line to PA.00 pin */


  GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource0);


 

  /* Configure EXTI0 line */


  EXTI_InitStructure.EXTI_Line = EXTI_Line0;


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


  NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;


  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;


  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;


  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;


  NVIC_Init(&NVIC_InitStructure);


}


After copying, many errors are found, which need to be solved one by one. The error solution in the figure below: LIB adds two library files misc.c and stm32f10x_exit.c.



Interrupt handling function:


void EXTI3_IRQHandler(void)


{


  if (EXTI_GetITStatus(EXTI_Line3) != RESET)


  {


    /* Turn ON LED2 */


GPIOD->BRR |= (1<<12);




    /* Clear the  EXTI line 0 pending bit */


    EXTI_ClearITPendingBit(EXTI_Line3);


  }


Remember to add EXTI3_Config() in the main program. You can also follow the example on the official website to do the flip. The specific implementation is:


Set GPIOD->BRR |= (1<


Finally, please note that when configuring the interrupt, we set the external interrupt to be triggered on the rising edge: EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;


Keywords:STM32F103 Reference address:STM32F103 Programming - 7-Pin Input Function - Button (Interrupt)

Previous article:STM32_Button control LED polling
Next article:Using STM32's Systick interrupt to achieve key debounce

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号