Reputation: 585
Print to console is always "255" I ran code to check for peripherals it saw a device on 0x50.
I don't understand how the EEPROM knows what memory address to read. Neither requestFrom()
nor read()
pass a value for the memory address to start reading. Is there an address pointer that is left in position from the write?
Any suggestions?
#include <Wire.h>
int i2cAdd = 0x50;
int memAdd = 100;
int valueWrite = 9;
int valueLength = 1;
int valueRead=0;
void setup() {
Serial.begin(9600);
Serial.println("Start bus");
Wire.begin();
delay(100);
Serial.println("Start Write");
Wire.beginTransmission(i2cAdd);
Wire.write(valueWrite);
Wire.endTransmission();
Serial.println("End Write");
delay(100);
Serial.println("Start read");
Wire.requestFrom(i2cAdd, valueLength);
valueRead = Wire.read();
Serial.println(valueRead);
Serial.println("End read");
} // setup
void loop() {}
Upvotes: 0
Views: 574
Reputation: 11
I recommend using a library for arduino I2C EEPROM. https://github.com/RobTillaart/I2C_EEPROM
Upvotes: 1
Reputation: 1714
You need to specify the read or write address as TWO bytes, first the most-significant byte, then the least-significant byte. You aren't specifying which address to read/write.
// Write one byte 'valueWrite' to specified address 'memAdd'
Wire.beginTransmission(i2cAdd);
Wire.write((int)(memAdd >> 8)); // write MSB of address to write
Wire.write((int)(memAdd & 0xFF)); // write LSB of address to write
Wire.write(valueWrite); // write one byte
Wire.endTransmission();
// Specify read address
Wire.beginTransmission(i2cAdd);
Wire.write((int)(memAdd >> 8)); // write MSB of address to read
Wire.write((int)(memAdd & 0xFF)); // write LSB of address to read
Wire.endTransmission();
// read a byte from the specified address
byte rdata = 0xFF;
Wire.requestFrom(i2cAdd, 1);
if (Wire.available())
rdata = Wire.read();
Upvotes: 1