I'm having some problems with an ATtiny45, TinyWireS, and i2c. I'm running at 3.3 volts, and I'm using 4.7k ohm pullup resistors.
I'm trying to use an ATtiny45 as a slave device to read two infrared sensors in a line following application. It seems the master will function for one or two loop() cycles, however, it doesn't receive any data. (Or at least, doesn't output any data in the serial)
// Wire Master Reader
// by Nicholas Zambetti <http://www.zambetti.com>
// Demonstrates use of the Wire library
// Reads data from an I2C/TWI slave device
// Refer to the "Wire Slave Sender" example for use with this
// Created 29 March 2006
// This example code is in the public domain.
#include <Wire.h>
void setup()
{
Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(9600); // start serial for output
delay(1000);
//Wire.beginTransmission(0x02);
//Wire.write(0x03);
//Wire.endTransmission();
pinMode(RED_LED, OUTPUT);
digitalWrite(RED_LED, LOW);
}
void loop()
{
Wire.requestFrom(0x02, 2); // request 6 bytes from slave device #2
while(Wire.available()) // slave may send less than requested
{
char c = Wire.read(); // receive a byte as character
Serial.print(c); // print the character
}
digitalWrite(RED_LED, HIGH);
delay(250);
digitalWrite(RED_LED, LOW);
delay(250);
}
The Slave Code does get past the EEPROM.write(); function, so, I don't believe that is the case. Since I don't have experience with the ATtiny, I left it all there (sorry, I know), just in case there was something else which would cause an error...
I should add, I was able to successfully (or at least it seems that way) run the program on a different device using the Wire library instead of the TinyWireS library. That leads me to believe it's an issue with the TinyWireS library or my implementation of it...
I changed my code to match the examples posted and it works.
I think my issue was how I was responding to requests from the master. I would send a request for multiple bytes from the slave, but, use multiple TinyWireS.send() functions for each request. I changed my code to request 1 byte, multiple times (as in the example) to cycle through all the data I want and it works