Possible to adapt Wire.c to work on attiny45?

Hi there.

Sorry, this is slightly off-topic, but couldn’t fine any better place to ask this question.

I have a few Blinkm smart leds. A BlinkM basically is an RGB led connected to an Attiny45 atmel chip.
I’m going to reflash those great gizmos, and wish to use them as either Masters or Slaves on a I2C bus.

Given the sheer simplicity of use of Wire library, I’d like to reuse the code to run on the ATtiny45. Does anyone know
if it is just matter of tweaking some parameters in twi.c (which is coded around arduino’s ATmega168) or else if is necessary to
write a library from scratch?

Well, any help, or pointers to will be much appreciated.

Matteo Caprari

Hi Matteo,

wire.c is coded for use with a micro that has the TWI engine in it - which the ATMega8m mega16 and most other larger devices have.

In the ATtiny45 you have to use the USI (Universal Serial Interface) in TWI mode, so basically the code wont work. I done this, based on code that I got form another user on AVRfreaks http://avrfreaks.net. I have posted the zip file at: http://www.siliconrailway.com/resources/ATtiny45 i2c.zip. In the zip file you will find code that should support TWI/I2C on any AVR that has a USI peripheral.

On the Atmel website you will also find two application notes, AVR310 and AVR312, which have source code in them as well. Blakes work is, if I recall, based on those app notes and I have successfully used Blakes code in a number of applications.

Good luck!

John http://siliconrailway.com home of LEDuino

Thanks John!

All great pointers, I'll start digging deeper and find my into it. I was particularly confused about TWI vs USI, now clouds are clearing.

Just one thing, the file is not downloadable. Could you help somehow, maybe attaching it here or to a private mail as you prefer?

Thank mate.

I found the file. Didn't account for a space in the name.

Good stuff, thanks.