damellis / attiny

ATtiny microcontroller support for the Arduino IDE
720 stars 226 forks source link

Wire.h fails #118

Open aldenkeshap opened 7 years ago

aldenkeshap commented 7 years ago

I am using code similar to this (minus Serial). All other tests have worked. The error message I get is quite long, but it is here.

Ted-CAcert commented 7 years ago

Just ran into the same problem.

From what I found out, the ATtiny (at least the x5 variants, I don't know the x4 ones) supports TWI but implementation is quite different from the other AVR chips. While ATmega chips support a dedicated TWI module, ATtiny has a "Universal Serial interface" (USI), which can be used to implement TWI and SPI interfaces (and other things).

ATmega TWI and ATtiny USI use different registers, so the Wire library will fail to compile for ATtiny.

To me it looks like the low level part of the Wire library (twi.c and twi.h) would have to be re-implemented to support ATtiny.

Ted-CAcert commented 7 years ago

After looking a bit more I found http://playground.arduino.cc/Code/USIi2c

There are several related repositories on GitHub, like https://github.com/adafruit/TinyWireM and https://github.com/rambo/TinyWire and several more. At this point I don't have an idea about which one is suited for which purpose.

Another options seems to be the USIWire library https://github.com/puuu/USIWire which is part of the 1.8.3 IDE installation package.

Ted-CAcert commented 7 years ago

FYI: The USIWire library worked well for my project, which has to fetch data from an Si7021 humidity sensor.

himijendrix24 commented 4 years ago

I just tried the adafruit TinyWireM library to use an attiny85 as a i2c-master and it did not work. No compile-errors, but connection to slave never worked.

In the end i got it running by just changing this newer core: https://github.com/SpenceKonde/ATTinyCore