STM32库函数EXTI_GetFlagStatus和EXTI_GetITStatus的区别

1、一句话概述他们之间的区别就是:

一个是获取状态的,一个是获取中断的。

EXTI_GetFlagStatus 的作用是检查指定的外部中断线的标志是否被置位;

而 EXTI_GetITStatus 的作用是检查指定外部中断线的状态是否有效。
 

2.两个函数库函数解析

【库函数 EXTI_GetFlagStatus】

/**
  * @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)
{
	FlagStatus bitstatus = RESET;
	/* Check the parameters */
	assert_param(IS_GET_EXTI_LINE(EXTI_Line));
   
	if ((EXTI->PR & EXTI_Line) != (uint32_t)RESET) {
		bitstatus = SET;
	}
	else {
		bitstatus = RESET;
	}
	return bitstatus;
}

【库函数 EXTI_GetITStatus】

/**
  * @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)
{
	ITStatus bitstatus = RESET;
	uint32_t enablestatus = 0;
	/* Check the parameters */
	assert_param(IS_GET_EXTI_LINE(EXTI_Line));
 
	enablestatus =  EXTI->IMR & EXTI_Line;
	if (((EXTI->PR & EXTI_Line) != (uint32_t)RESET) && (enablestatus != (uint32_t)RESET)) {
		bitstatus = SET;
	}
	else {
		bitstatus = RESET;
	}
	return bitstatus;
}

可以看到区别在于 EXTI_GetITStatus 比 EXTI_GetFlagStatus 多做了一个判断:

enablestatus =  EXTI->IMR & EXTI_Line;
if (((EXTI->PR & EXTI_Line) != (uint32_t)RESET) && (enablestatus != (uint32_t)RESET)) 

EXTI->PR 是 STM32 的挂起寄存器(EXTI_PR),其中的各个位被称为挂起位(Pending bit)。当外部中断线上发生了选择的边沿事件时,EXTI_PR 中相应的 Pending 位被置‘1’,也就是上面提到的 Flag。

而 EXTI->IMR 是中断屏蔽寄存器(EXTI_IMR),其中各个位表示相应中断线上的中断屏蔽。‘0’表示屏蔽来自线x上的中断请求,‘1’开放来自线x上的中断请求。

所以,EXTI_GetFlagStatus 只是纯粹读取中断标志位的状态,但是不一定会响应中断(EXT_IMR 寄存器对该中断进行屏蔽);而 EXTI_GetITStatus 除了读取中断标志位,还查看 EXT_IMR 寄存器是否对该中断进行屏蔽,在中断挂起 & 没有屏蔽的情况下就会响应中断。
 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值