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?