attiny icon indicating copy to clipboard operation
attiny copied to clipboard

Wire.h fails

Open aldenkeshap opened this issue 8 years ago • 4 comments

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.

aldenkeshap avatar Aug 01 '17 02:08 aldenkeshap

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 avatar Aug 01 '17 22:08 Ted-CAcert

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 avatar Aug 02 '17 09:08 Ted-CAcert

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

Ted-CAcert avatar Aug 06 '17 20:08 Ted-CAcert

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

himijendrix24 avatar Oct 14 '19 11:10 himijendrix24