Two-wire (I2C) communication between ATtiny85 and EEPROM

Dear forum members,

I’m learning to program ATtiny chips using AVR-C. I’m trying to have an ATtiny85 chip read from EEPROM using two-wire interface (I2C). With an Arduino, this is not a problem. You can use the with the Wire.h library for two-wire communication. However, I don’t know how to do this in AVR-C.

I’d like to make a circuit where where the ATtiny85 reads a byte at address x of the EEPROM, through the two-wire interface and then displays the 8 bits on 8 LEDs using a shift register.

In the datasheet of the ATtiny85 I found that pin 5 and 7 can be used for two-wire, as data and clock respectively. I’m using an Atmel AT24C256 EEPROM (datasheet)

(I put resistors between the LEDs and ground but they’re not shown in the image)

I already wrote a function shiftNumber() that displays a byte on the 8 LEDs using the shift register. So shiftNumber(255) turns all the LEDs go on and shiftNumber(0) turns all the LEDs off. (I put the code here for those interested).

How can I let the ATtiny85 read a byte of data from the EEPROM? I’d like to use AVR-C. Should I use the twi.h library? Could you give me a hint for the code?

You need the tinywire library, or whatever it's called, that uses the USI to do I2C, since the 84 and 85 don't have hardware I2C.

There are also full software implementations usable on boards that have no hardware I2C or USI (ex, some of the fancier ATTiny's that have builtin I2C slave and SPI master, but no USI or I2C master)

Some .1 uF bypass caps .. like 1 where the power enters the board and 1 per IC would be in order too..


Docedison: Some .1 uF bypass caps .. like 1 where the power enters the board and 1 per IC would be in order too..


Dear Doc,

This is all a bit new to me. I didn't know what a bypass cap is, but I googled it. Are you suggestiong that I put a 100 nF capacitor between the Vcc and GND of each microchip?

Yes. Always, every IC gets it's own 0.1uf cap right next to the chip (as close as possible), if it has more than one supply pin, one cap on each (unless specified otherwise in the datasheet - sometimes they have specific instructions).