0
我正在嘗試使用TinyWireS庫通過I2C在Arduino和AtTiny85之間進行通信。我只需要Arduino發送命令給AtTiny,它不需要回話。使用TinyWireS通過I2C在ATtiny85和Arduino之間通信時出錯
Arduino的使用電線庫,並能正常工作,但每當我試圖編譯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;
}
當你刪除'#include'行時會發生什麼?另外根據https://github.com/rambo/TinyWire/blob/master/TinyWireS/examples/attiny85_i2c_slave/attiny85_i2c_slave.ino,您必須在包含'TinyWireS.h'之前定義'I2C_SLAVE_ADDR' *。 –