STM32--EXIT例子

来源:互联网 发布:云计算的资源类型 编辑:程序博客网 时间:2024/06/14 18:18

通用I/O端连接到16个外部中断/事件线上,所有IO都可以作为中断输入引脚。

(注意:同一个IO位只能分配一个IO,例如:PA0,PB0,...PG0只能选择一个作为EXIT0,即不能同时作为中断输入引脚)

EXTI9_5_IRQn表示----External Line[9:5] Interrupts

 

GPB.9配置外外部中断IO口

 

void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;

#ifdef  VECT_TAB_RAM 
  /* Set the Vector Table base location at 0x20000000 */
  NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
#else  /* VECT_TAB_FLASH  */
  /* Set the Vector Table base location at 0x08000000 */
  NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);  
#endif

  /* Configure one bit for preemption priority */
  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
 
  /* Enable the EXTI9_5 Interrupt */
  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);
}

 

void GPIO_Configuration(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;

   /* Enable GPIO clock */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO, ENABLE);


  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  GPIO_Init(GPIOB, &GPIO_InitStructure);
 
 
}

 

 /* Connect Key Button EXTI Line to Key Button GPIO Pin */
  GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource9);

   /* Configure Key Button EXTI Line to generate an interrupt on falling edge */ 
  EXTI_InitStructure.EXTI_Line = EXTI_Line9;
  EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
  EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  EXTI_Init(&EXTI_InitStructure);

 

 

 

void EXTI9_5_IRQHandler(void)
{
   if(EXTI_GetITStatus(EXTI_Line9) != RESET)
   {
      EXTI_ClearITPendingBit(EXTI_Line9);
   }
}

原创粉丝点击