I have a 4Kbits EEPROM, and I am trying to interface the EEPROM with teensy 3.2.
The datasheet I used can be found here.
My hardware connections are as follow.
teensy <-----------> EEPROM
+3.3V <-----------> VCC
GND <-----------> GND
GND <-----------> A0
GND <-----------> A1
GND <-----------> A2
GND <-----------> WP
SDA <-----------> SDA
SDL <-----------> SDL
I tried using a code to interact with the EEPROM through the I2C interface.
My code used are as follows:
#include <Wire.h>
int i2c_eeprom_read_byte( int deviceaddress, unsigned int eeaddress ) {
int rdata = 0xFF;
Wire.beginTransmission(deviceaddress);
Wire.write((int)(eeaddress >> 8)); // MSB
Wire.write((int)(eeaddress & 0xFF)); // LSB
Wire.endTransmission();
Wire.requestFrom(deviceaddress,1);
if (Wire.available()) rdata = Wire.read();
return rdata;
}
void setup()
{
Wire.begin(); // initialise the connection
Serial.begin(9600);
}
void loop()
{
int addr=0; //first address
int b = i2c_eeprom_read_byte(0x50, 0); // access the first address from the memory
while (addr!=512)
{
Serial.print(b); //print content to serial port
addr++; //increase address
b = i2c_eeprom_read_byte(0x50, addr); //access an address from the memory
}
Serial.println(" ");
delay(2000);
}
However, I am only getting 255 printed from all location of the EEPROM. I am quite certain that the EEPROM contain data in it.
I checked through the code, and is not able to pinpoint any reason for the print out.
May I seek your opinion on what may be causing this program to only print 255.
Thank you.
