Raspberry pi 和 Atmega 328 之间的硬件中断

Hardware interrupt between Raspberry pi and Atmega 328

我已将我的 RPI 和 atmega328 连接在一起,以控​​制我的 arduino 上事件的开始。为此,GPIO 25 (RPI) 直接连接到 pin7 (Arduino PD7)。我在 RPI 上有一个 python 脚本 将 GPIO 25 设置为高然后回到低:

    import RPi.GPIO as GPIO 

    GPIO.setmode(GPIO.BCM)
    GPIO.setup(25, GPIO.OUT)

    GPIO.output(25, 1)
    #Do some stuff
    GPIO.output(25, 0)

arduino 正在循环等待按下物理按钮或通过 RPI 将 pin7 设置为高电平:

const int interrupt = 7;
const int button = 13;
const int led = 9;

void setup() {
  Serial.begin(9600);
  pinMode(interrupt, INPUT);
  pinMode(button,INPUT);
  pinMode(led, OUTPUT);
  digitalWrite(led, LOW);
}

void loop() {
  bool on = false;
  bool buttonOn = false;

  while (!on || !buttonOn) {
    on = digitalRead(interrupt);
    buttonOn = digitalRead(button);
    digitalWrite(led, LOW);
  }
  digitalWrite(led, HIGH);
  delay(1000);
}

不幸的是,现在这行不通了。我已经检查了 atmega328 (https://learn.sparkfun.com/tutorials/logic-levels) 的逻辑电平,似乎 3.3V 对高信号来说已经足够了。

我是不是漏掉了上拉/下拉阻力?我知道 atmega 上的 PD7 指定如下:

Port D is an 8-bit bi-directional I/O port with internal pull-up resistors (selected for each bit). The Port D output buffers have symmetrical drive characteristics with both high sink and source capability. As inputs, Port D pins that are externally pulled low will source current if the pull-up resistors are activated. The Port D pins are tristated when a reset condition becomes active, even if the clock is not running.

编辑: 我做了更多测试,并且正确地获得了 HIGH 或 LOW 值。问题似乎来自:

while ((!on) || (!buttonOn)) {

Arduino 和 while 循环中的 OR 运算符是否存在问题?即使一个条件为真而另一个为假,它也永远不会跳出循环。

3.3 v 输出应该可以将 Arduino 输入调高。

您可能有接线问题,或者您的 raspberry pi 速度太快以至于 arduino 错过了脉冲。

更改 raspberry pi 上的程序,使输出保持高电平很长时间(例如 10)秒,以便您可以用万用表测量它以查看您设置的引脚是否正确。

Arduino 现在能看到输入了吗?

while ((!on) || (!buttonOn)) {
}

只要其中一个变量为假,该循环就会运行。 昨天不知为何我以为你在看你的代码时读了两次中断引脚。