STM32—EXTI(标准库)

      EXTI:STM32支持所有IO端口触发外部中断,但是每个端口只能有一个PIn(如PA1和PB1..PN1只允许一个)

     注意:EXTI不需要开启时钟

1.开启GPIO时钟,AFIO时钟:  前者配置IO口模式,后者完成EXTI引脚功能到普通引脚的映射.

   

/**
  * @brief  Enables or disables the High Speed APB (APB2) peripheral clock.
  * @param  RCC_APB2Periph: specifies the APB2 peripheral to gates its clock.
  *   This parameter can be any combination of the following values:
  *     @arg RCC_APB2Periph_AFIO, RCC_APB2Periph_GPIOA, RCC_APB2Periph_GPIOB,
  *          RCC_APB2Periph_GPIOC, RCC_APB2Periph_GPIOD, RCC_APB2Periph_GPIOE,
  *          RCC_APB2Periph_GPIOF, RCC_APB2Periph_GPIOG, RCC_APB2Periph_ADC1,
  *          RCC_APB2Periph_ADC2, RCC_APB2Periph_TIM1, RCC_APB2Periph_SPI1,
  *          RCC_APB2Periph_TIM8, RCC_APB2Periph_USART1, RCC_APB2Periph_ADC3,
  *          RCC_APB2Periph_TIM15, RCC_APB2Periph_TIM16, RCC_APB2Periph_TIM17,
  *          RCC_APB2Periph_TIM9, RCC_APB2Periph_TIM10, RCC_APB2Periph_TIM11     
  * @param  NewState: new state of the specified peripheral clock.
  *   This parameter can be: ENABLE or DISABLE.
  * @retval None
  */


void RCC_APB2PeriphClockCmd(uint32_t RCC_APB2Periph, FunctionalState NewState)
{
  ........
}

开启  GPIO AFIO 时钟
  • 将EXTI引脚映射至GPIO引脚--------- 在 gpio函数库中

EXTI 引脚映射 : void GPIO_EXTILineConfig(uint8_t GPIO_PortSource, uint8_t GPIO_PinSource)

/**
  * @brief  Selects the GPIO pin used as EXTI Line.
  * @param  GPIO_PortSource: selects the GPIO port to be used as source for EXTI lines.
  *   This parameter can be GPIO_PortSourceGPIOx where x can be (A..G).
  * @param  GPIO_PinSource: specifies the EXTI line to be configured.
  *   This parameter can be GPIO_PinSourcex where x can be (0..15).
  * @retval None
  */


void GPIO_EXTILineConfig(uint8_t GPIO_PortSource, uint8_t GPIO_PinSource)
{
  .................
}


将  EXTI引脚 映射到  GPIOx端口的某个引脚

  2.EXTI函数库讲解:在固件库—— exti 函数库中

  •    初始化函数:   void EXTI_Init(EXTI_InitTypeDef* EXTI_InitStruct)
/**
  * @brief  Initializes the EXTI peripheral according to the specified
  *         parameters in the EXTI_InitStruct.
  * @param  EXTI_InitStruct: pointer to a EXTI_InitTypeDef structure
  *         that contains the configuration information for the EXTI peripheral.
  * @retval None
  */



void EXTI_Init(EXTI_InitTypeDef* EXTI_InitStruct)
{
  .............
}


EXTI_InitStruct.EXTI_Line      :   选择外部中断引脚,必须与映射引脚号相同

EXTI_InitStruct.EXTI_LineCmd   :   是否使能引脚状态

EXTI_InitStruct.EXTI_Mode      :   选择中断的模式

EXTI_InitStruct.EXTI_Trigger   :   选择中断触发的方式
  • 初始化配置函数:  void EXTI_StructInit(EXTI_InitTypeDef* EXTI_InitStruct)
/**
  * @brief  Fills each EXTI_InitStruct member with its reset value.
  * @param  EXTI_InitStruct: pointer to a EXTI_InitTypeDef structure which will
  *         be initialized.
  * @retval None
  */


void EXTI_StructInit(EXTI_InitTypeDef* EXTI_InitStruct)
{
  .....
}



将EXTI初始化配置 : 
  • 清除初始化函数: void  EXTI_DeInit(void)
/**
  * @brief  Deinitializes the EXTI peripheral registers to their default reset values.
  * @param  None
  * @retval None
  */


void EXTI_DeInit(void)
{
  ........
}



清除初始化
  • 软件触发中断:   void EXTI_GenerateSWInterrupt(uint32_t EXTI_Line)
/**
  * @brief  Generates a Software interrupt.
  * @param  EXTI_Line: specifies the EXTI lines to be enabled or disabled.
  *   This parameter can be any combination of EXTI_Linex where x can be (0..19).
  * @retval None
  */



void EXTI_GenerateSWInterrupt(uint32_t EXTI_Line)
{
  /* Check the parameters */
  assert_param(IS_EXTI_LINE(EXTI_Line));
  
  EXTI->SWIER |= EXTI_Line;
}


软件触发一次中断
  • 标志位函数1:  FlagStatus EXTI_GetFlagStatus(uint32_t EXTI_Line)
/**
  * @brief  Checks whether the specified EXTI line flag is set or not.
  * @param  EXTI_Line: specifies the EXTI line flag to check.
  *   This parameter can be:
  *     @arg EXTI_Linex: External interrupt line x where x(0..19)
  * @retval The new state of EXTI_Line (SET or RESET).
  */


FlagStatus EXTI_GetFlagStatus(uint32_t EXTI_Line)
{
   .........
}


查看 所选通道的挂起标志位是否被 置1

此函数一般用作中断外
  • 标志位函数2:  void   EXTI_ClearFlag(uint32_t EXTI_Line)
/**
  * @brief  Clears the EXTI's line pending flags.
  * @param  EXTI_Line: specifies the EXTI lines flags to clear.
  *   This parameter can be any combination of EXTI_Linex where x can be (0..19).
  * @retval None
  */


void EXTI_ClearFlag(uint32_t EXTI_Line)
{
   ......
}


清除 挂起 标志位

此函数一般用作中断外
  • 标志位函数3:    ITStatus  EXTI_GetITStatus(uint32_t EXTI_Line)
/**
  * @brief  Checks whether the specified EXTI line is asserted or not.
  * @param  EXTI_Line: specifies the EXTI line to check.
  *   This parameter can be:
  *     @arg EXTI_Linex: External interrupt line x where x(0..19)
  * @retval The new state of EXTI_Line (SET or RESET).
  */


ITStatus EXTI_GetITStatus(uint32_t EXTI_Line)
{
 ........
}



读取中断标志位是否被 置1

此函数一般中断内调用
  • 标志位函数4:    void  EXTI_ClearITPendingBit(uint32_t EXTI_Line)
/**
  * @brief  Clears the EXTI's line pending bits.
  * @param  EXTI_Line: specifies the EXTI lines to clear.
  *   This parameter can be any combination of EXTI_Linex where x can be (0..19).
  * @retval None
  */


void EXTI_ClearITPendingBit(uint32_t EXTI_Line)
{
   .......
}



清除中断标志位

此函数一般中断内调用

中断函数:STM32中中断函数是固定--------在 startup_stm32f10x_hd.s文件中(启动文件)

  • EXTI的中断函数有:
EXTI0_IRQHandler

EXTI1_IRQHandler

EXTI2_IRQHandler

EXTI3_IRQHandler

EXTI4_IRQHandler

EXTI9_5_IRQHandler

EXTI15_10_IRQHandler

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值