I'm trying to use ATTiny85s for a few applications that require communication with a "host" (an Arduino).
To do so, using I2C (TWI) seems most sensible, so I use the Wire library on the Arduino and TinyWireS on the Tiny85.
Sending Data Arduino->Tiny85 works fine, however, as soon as I post a WireRequest(ADDR,1), the Tiny85 holds the SDA line low and blocks the bus. I saw this in a few places but never found a good explanation. I've measured drain to the Tiny85's SDA line and in this blocking low state, it drains about 1.2mA which is consistent with an open drain and the pullup resistors to 5V, so I'm rather certain that it is, in fact, the Tiny holding the line low.
The SCL line is behaving all right.
Has anyone worked with this setup? Had Success with reading from the ATTiny?
Is there anyone working on an integrated TWI library for the Tiny?
Thanks
pj
Master code:
void loop()
{
byte byteRcvd=0;
if(digitalRead(A0)==LOW) //switch attached to A0 to trigger transmission
{
x++;
Wire.beginTransmission(0x04); // transmit to device #4
Serial.print("sending ");
Serial.println(x);
digitalWrite(7,HIGH); //LED attached to Pin 7 to show transfer has happened
Wire.write(x);
Serial.println("sent");
Wire.endTransmission();
delay(50);
digitalWrite(7,LOW);
while(digitalRead(A0)==LOW); //avoid "autofire"
// with these lines in, transmission will not succeed after first call to Wire.requestFrom()
// SDA will be pulled LOW by ATTiny85 and only released upon reset to the Tiny.
// I have no equipment to analyze the data format on the TWI, but I assume that the request is successfully sent
// to the Tiny which makes it change it's state.
Serial.println("before requestFrom");
Wire.requestFrom(4,1);
Serial.println("after requestFrom");
delay(100);
}