Hello
I decided to use I2C EEPROM ( 24LC64 ) , which has 46 kb of memory inside . I needed peace of code which would be able to write some info into it and then read from it . So , I found such a code on Youtube . code is performing well :
#include <Wire.h>
int data = 0;
byte low = 0x00, high = 0x00;
int pin = 2;
void setup ()
{
pinMode (pin,INPUT);
Serial.begin (9600);
Wire.begin ();
}
void loop ()
{
data = digitalRead (pin);
Wire.beginTransmission (0x50);
Wire.write (high);
Wire.write (low);
Wire.write (data);
Wire.endTransmission ();
delay (5);
Wire.beginTransmission (0x50);
Wire.write (high);
Wire.write (low);
Wire.endTransmission ();
Wire.requestFrom (0x50,1);
delay (5);
Serial.print (int (Wire.read ()));
Serial.print (" Adress ");
Serial.print (int (high));
Serial.print (" ");
Serial.println (int (low));
if (low = 255) high ++;
low ++;
}
Then I am interested in why I need double communication when in first communication is written data and in another there is no data writing ,so why is this necessary ? then what does Wire.requestFrom (0x50,1) function does and what is its second argument ? I also would like to know how memory is allocated in this EEPROM . I write in 256 bit and then starting from new block of memory or how ?
Look at the if statement, should this not be ==
The second argument is how many bytes it needs to read from the device.
ok , I missed an error . and how info is written in it and much bit can I write into it ? also why there is as 256 bits and starting again . can I write info in it like in shift trigger ? or how ?
also why there is as 256 bits and starting again
No it uses all 64k of address space.
can I write info in it like in shift trigger
What is a shift trigger?
so , like this low address to be 0x00 and high to be till 64 kb ( 1024 * 64 ) ?
for example what kind of number could be data ( from 0 to 255 ? ) ?
and can you give me some additional information (web site tutorial) , about writeing and reading from EEPROM ?
Also I would like to know how should I write code for only reading and writing the info into the chip .
thank you in advance .
The address is two bytes called high and low.
That code increments low until it overflows, that is wraps round to zero after the value of 255 is incremented. Then the high byte is incremented and stays at that value while low goes round again from 0 to 255.
You are writing bytes to the EEPROM that is only numbers from 0 to 255, that is all that one address location will take.
If you want to store bigger numbers then you must split it up into bytes and write one byte per address.
thank you very much , ok , I have understood everything.
and what happens if I increment low till 1024 and after that high will be incremented by one , and low will start again . is this possible and how much time it will work ? till 64 ? because 64 * 1024 = 64 KB ?
The variables high and low are only byte values so the biggest they can get is to 255 each.
This is 64K of space.
When high is at 255 and gets incremented it will wrap round to zero