stm8s 在arduino编辑器中使用外中断

转贴自:

https://www.reddit.com/r/STM8/comments/jbq023/interrupts_on_stm8_with_sduino/

亲测好用,以下是原文:

I did it! With some googling, sleuthing, and trial-and-error, I figured it out.

With STM8 sduino, attachInterrupt works but it's not quite like on a normal arduino.

Interrupts are separate per PORT, not per pin. Each port has multiple pins. PA1, PA2 are on port A, PC3-PC7 are on port C etc.

Use pinMode to designate the pin as input, so that digitalRead can keep working in case you need it.

After that, you must call GPIO_Init (an STM8-specific API function) to actually enable interrupts for a particular pin.

Then, you must disable interrupts (as per the official documentation, and it really doesn't work otherwise!) and call EXTI_SetExtIntSensitivity to set the interrupt trigger type on that entire port.

The you can re-enable interrupts and finally call attachInterrupt(). See my example below, this code works for me on my STM8S003F3.

Hope this saves someone some time.

void ISR()
{ //your code here }

void setup()
{
  pinMode(2,INPUT);
  GPIO_Init(GPIOA, GPIO_PIN_3, GPIO_MODE_IN_FL_IT);
  disableInterrupts();
  EXTI_SetExtIntSensitivity( EXTI_PORT_GPIOA, EXTI_SENSITIVITY_RISE_ONLY);
  enableInterrupts();
  attachInterrupt(INT_PORTA & 0xFF,ISR,0);
}
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值