I'm trying to write to a separate device's EEPROM to configure the behavior is the device, and am controlling the device with an Arduino Uno.
As according to this webpage, my SCK is connected to pin 13 and my SDA connected to pin 11.
I have two functions, i2c_eeprom_write_byte
and i2c_eeprom_read_byte
, taken from this example.
void i2c_eeprom_write_byte( int deviceaddress, unsigned int eeaddress, byte data ) {
Wire.begin(deviceaddress); // MUST INCLUDE, otherwise Wire.endTransmission hangs
// called once, in setup
int rdata = data;
Wire.beginTransmission(deviceaddress);
Wire.write((int)(eeaddress >> 8)); // MSB
Wire.write((int)(eeaddress & 0xFF)); // LSB
Wire.write(rdata);
Wire.endTransmission(false);
}
byte i2c_eeprom_read_byte( int deviceaddress, unsigned int eeaddress ) {
byte rdata = 0xFF;
Wire.beginTransmission(deviceaddress);
Wire.write((int)(eeaddress >> 8)); // MSB
Wire.write((int)(eeaddress & 0xFF)); // LSB
Wire.endTransmission();
delay(10);
Wire.requestFrom(deviceaddress,1);
int avail = Wire.available();
Serial.println(avail);
if (Wire.available()) rdata = Wire.read();
// there's a bug here with Wire.available. It's returning 0 (ie, 0 bytes to be read),
// when it should be returning 1, since I want 1 byte.
return rdata;
}
My problem is that Wire.available()
always returns a 0, meaning that the slave device isn't sending anything to the master device, the Arduino.
How do I read from the slave device?