AtTiny85 和 Arduino (I2C) 之间的简单通信

simple communication between AtTiny85 and Arduino (I2C)

嗨,我想通过 I2C 将 arduino pro mini 连接到我的 AtTiny85。

arduino 应该告诉 attiny 打开或关闭 LED。 arduino 设法打开了我 attiny 上的 led,但它永远不会熄灭。

我不知道为什么?

这是我的主从代码:

大师:

#include <Wire.h>
#define device (1)

void setup() {
  // put your setup code here, to run once:
  Wire.begin();
}

void loop() {
  // put your main code here, to run repeatedly:
  Wire.beginTransmission(device);
  Wire.write(1);
  Wire.endTransmission();
  delay(2000);
  Wire.write(0);
  Wire.endTransmission();
  delay(2000);
}

奴隶:

#include <TinyWireS.h>
#include <usiTwiSlave.h>
#define output (4)
#define I2C_SLAVE_ADDR (1)


void setup() {
  // put your setup code here, to run once:
  TinyWireS.begin(I2C_SLAVE_ADDR);
  pinMode(output, OUTPUT);
}

volatile byte msg = 0;

void loop() {
  if(TinyWireS.available())
    msg = TinyWireS.receive();

  if(msg == 1)
    digitalWrite(output, HIGH);
  else if(msg == 0)
    digitalWrite(output, LOW);
  else
    msg = 0;
}

我终于找到了我的错误: 当我这样做时:Wire.write(0); 我忘了开始传输:Wire.beginTransmission(device);