Have a problem withe external EEPROM

Hello i'm using due + 24c64 (8192x8) , i want to know i can store only 255 one one address while i using 64k ic . so please tell me why it storing till 255 ( i don't want use low byte and high byte concept because i'm using 24c64)

int y
void setup()
{
  Wire.begin();
  analogWrite(6,inten);  //Display intensity
  lcd.begin(20,4);
  lcd.print(" last Count: ");
  y= readAddress(1);
  lcd.print(y);
 delay(500);
  lcd.clear();
  
}
void writeAddress(int address, int val)
{
  Wire.beginTransmission(EEPROM_I2C_ADDRESS);
  Wire.write((int)(address >> 8));   // MSB
  Wire.write((int)(address &  0xFF));   // lSB
  
  Wire.write(val);
  Wire.endTransmission();

  delay(5);
}
int readAddress(int address)
{
  int rData = 0xFF;
  
  Wire.beginTransmission(EEPROM_I2C_ADDRESS);
 Wire.write((int)(address >> 8));   // MSB
  Wire.write((int)(address &  0xFF));   // LSB
 
  Wire.endTransmission();  


  Wire.requestFrom(EEPROM_I2C_ADDRESS, address);  

  rData =  Wire.read();

  return rData;
}

void loop()
{
lcd.setCursor(0,0);
lcd.print(y);
writeAddress(1,y);
y++;

delay(200);
}

Because the upper limit of (unsigned) 1 byte is 255. :hushed:

As far as you can see in your code, you are reading/writing just 1 byte to the EEPROM at calling your function.

There is also a problem with the read function.
The code is working, probably because you are lucky...

I don't understand that sentence.

sir please provide solution

i want to store number greater then 255. most of people suggest to split data in low ans high byte and then store. but i'm using 24c64 which have capacity to store large number.

OK, thanks for the explanation.
Let us know how that goes

please help me..

So break down your larger number into byte-sized chunks and store them separately. That's exactly what the people are doing who suggest the use of a high and low byte. It works for them, why wouldn't it work for you?

it work for me .but why i should break data ? while i have large capacity memory.

It doesn't have to do with the capacity of your memory. It is related to the way in which data is transferred over I2C to the memory chip. I2C is based on byte-wise transfers, so everything you send over I2C you generally break up into individual bytes.

You can always write a function that accepts e.g. a float which is then broken up into 4 bytes inside the function which are then transmitted separately to the chip. That way it still works but in programming higher level functions you're not bothered by the process of breaking up etc.

1 Like

thank a lot , you give me fruitful reply.

You do not need to delete posts if you type something wrong, just edit the post - using the "pencil" icon underneath. :grin:

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.