我正在尝试使用TinyWireS库在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;
}
答案 0 :(得分:0)
Maximilian Gerhardt的评论是对的。您不应该再次加入<usiTwiSlave.h>
。 TinyWireS库的标题不使用#ifdef
- #def
括号。这通常可以确保没有任何内容被编译多次。
地址通过begin()
函数的参数提供给库。所以我认为,在奴隶的例子中,只是巧合,地址定义在包含之前。
顺便说一下:我从TinyWireS和TinyWireM库中创建了一个库。如果您有兴趣,请查看: https://github.com/lucullusTheOnly/TinyWire
FYI:I2C / TwoWire协议有保留地址,1是其中之一。将另一台设备添加到总线时,这可能会出现问题。