历史上的今天
今天是:2024年08月31日(星期六)
2018年08月31日 | STM32库函数EXTI_GetFlagStatus和EXTI_GetITStatus的区别
2018-08-31 来源:eefocus
在使用 STM32 的外部中断功能时,我们经常需要确认是否真的产生了外部中断,查看库函数,我们发现了这两个函数:EXTI_GetFlagStatus 和 EXTI_GetITStatus 。原型如下:
FlagStatus EXTI_GetFlagStatus ( uint32_t EXTI_Line );
ITStatus EXTI_GetITStatus ( uint32_t EXTI_Line );
可以看出,这两个函数是十分相似的,EXTI_GetFlagStatus 的作用是 Checks whether the specified EXTI line flag is set or not. 即检查指定的外部中断线的标志是否被置位;而 EXTI_GetITStatus 的作用是 Checks whether the specified EXTI line is asserted or not. 即检查指定外部中断线的状态是否有效。
也就是说前者是检查中断标志的,后者是检查中断状态的。我们追踪一下这两个库函数的实现即可发现区别。
【库函数 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 寄存器是否对该中断进行屏蔽,在中断挂起 & 没有屏蔽的情况下就会响应中断。
上一篇:STM32软件定时器的设计
史海拾趣
|
1)NorFlash可供使用的地址空间应该从0x0000开始吧。那么为什么在手册中在说明ID读取时,如下:manufacturer\'s ID 0000H(address) 00BFH(data) ; Device ID 0001H(address) 2782H(data) 。感到不 ...… 查看全部问答> |
|
void main(void) { unsigned char xdata* data dptr; unsigned char i,VOUT=0; float Y,Y1,Y2,X; while(1) { dptr=0x7ff8; ...… 查看全部问答> |
|
要设计产品,首先要确定用谁的LED封装结构;接下来考虑怎样适应这些封装形式; 由我们选择的机会不多,光学结构是建立在这些封装之上的;我们很多创意不能很好的发挥。下面介绍LED照明设计过程中的关键问题及分析。 一、半导体照明应用中存在 ...… 查看全部问答> |
|
最近用IAR4.2开发ST,发现它默认的缩进只有两个空格,像 if(a) { ? ?b; } 不知道能不能修改成默认有更多空格,比如四个,像 if(a) { ? ? ? ? b; } 求教!… 查看全部问答> |
|
430 能进行指数运算吗? 如果能该怎样实现?? #include <math.h> void main(void) { dou××e i; i=exp(1.5); } 但从 watch 中检测 i 值 ,显示 un××iala××e 怎么一回事?? 3ks… 查看全部问答> |




