我正在尝试使用 TinyWireS 库通过 I2C 在 Arduino 和 AtTiny85 之间进行通信。我只需要 Arduino 向 AtTiny 发送命令,它不需要回话。
Arduino 正在使用 Wire 库,它工作正常,但是每当我尝试编译 AtTiny85 代码时,它都会出现以下错误:
libraries\TinyWireS\TinyWireS.cpp.o (symbol from plugin): In function `usi_onReceiverPtr':
(.text+0x0): multiple definition of `usi_onReceiverPtr'
sketch\ATtiny_Servo.ino.cpp.o (symbol from plugin):(.text+0x0): first defined here
libraries\TinyWireS\TinyWireS.cpp.o (symbol from plugin): In function `usi_onReceiverPtr':
(.text+0x0): multiple definition of `usi_onRequestPtr'
sketch\ATtiny_Servo.ino.cpp.o (symbol from plugin):(.text+0x0): first defined here
libraries\TinyWireS\TinyWireS.cpp.o (symbol from plugin): In function `usi_onReceiverPtr':
(.text+0x0): multiple definition of `_onTwiDataRequest'
sketch\ATtiny_Servo.ino.cpp.o (symbol from plugin):(.text+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
exit status 1
Error compiling for board ATtiny25/45/85.
这是我的代码:
#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;
}