0
votes

I am attempting to communicate between an Arduino and an AtTiny85 with I2C using the TinyWireS library. I only need the Arduino to send commands to the AtTiny, it does not need to talk back.

The Arduino is using the Wire library, and it works fine, however whenever I try to compile the AtTiny85 code, it gives the following error:

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.

Here is my code:

#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;
}
1
What happens when you remove the #include <usiTwiSlave.h> line? Also according to github.com/rambo/TinyWire/blob/master/TinyWireS/examples/… you have to define I2C_SLAVE_ADDR before you include TinyWireS.h.Maximilian Gerhardt

1 Answers

0
votes

The comment of Maximilian Gerhardt is half right. You shouldn't include <usiTwiSlave.h> a second time. The header of the TinyWireS library doesn't use #ifdef-#def brackets. This normally ensures, that nothing is compiled more than one time. The address is given to the library through the parameter of the begin() function. So I think, in the slave example it is just coincidence, that the address definition stand before the include.

Btw: I made one library out of the TinyWireS and TinyWireM library. If you are interested, check it out: https://github.com/lucullusTheOnly/TinyWire

And FYI: The I2C/TwoWire Protocol has reserved addresses and 1 is one of them. This may get a problem, when adding another device to the bus.