STM8 GPIO外部中断的没有中断标志位.----是硬伤,直接想骂它的设计人员

2019-12-18 18:49发布

首先,端口的八个GPIO共用一个中断向量.
每个GPIO能够独立配置上升下降作为中断触发条件.
但是这个功能实际上没有太大用处,因为STM8的GPIO中断居然只有中断使能位,没有中断标志位!

举例说明:
想要在A1,A2口上实现两个必须上升沿触发中断的按钮或者外设,需要共用EXT_A的中断向量.
假设有一时间发生了EXT_A中断,进入了中断服务函数.现在没有中断标志位,直接导致要用很复杂的算法才能判断到底是哪个口上发生的中断.
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
41条回答
millwood0
2019-12-21 19:52
现在没有中断标志位,直接导致要用很复杂的算法才能判断到底是哪个口上发生的中断.


EXTI, unlike other interrupts, does not have its own status register / flag, as you indicated.

However, you can easily use a static variable to remember the previous state of the port and to determine which pins trigger the interrupt.

something like:

  1.   static unsigned char sPORTA=0; //porta shadow register
  2.   

  3.   tmp = PORTA ^ sPORTA; //which pins have changed -> pins that have changed will be 1
  4.   //alternatively to detect a falling edge
  5.   //tmp = (PORTA ^ sPORTA) & sPORTA; //which pins have a falling edge
  6.   sPORTA = PORTA;  //save portA's current reading
  7.   ...

复制代码you can further AND tmp with Px_CR2 register to just read the ones that you have activated for EXTI.

Unusual but not too complicated

一周热门 更多>