The 24LC256 EEPROM:
The Microchip 24LC256 is a 32K x 8 (256 Kbit) Serial Electrically Erasable PROM, capable of operation across a broad voltage range (1.7V to 5.5V). It has been developed for advanced, low-power applications such as personal communications or data acquisition.
This device also has a page write capability of up to 64 bytes of data. This device is capable of both random and sequential reads up to the 256K boundary. Functional address lines allow up to eight devices on the same bus, for up to 2 Mbit address space. This device is available in the standard 8-pin plastic DIP, SOIC, TSSOP, MSOP and DFN packages.
Features:
- Single Supply with Operation Down to 2.5V for 24LC256 Devices
- Low-Power CMOS Technology:
- – Active current 400 uA, typical
- – Standby current 100 nA, typical
- 2-Wire Serial Interface, I2C™ Compatible
- Cascadable up to Eight Devices
- Schmitt Trigger Inputs for Noise Suppression
- Output Slope Control to Eliminate Ground Bounce
- 100 kHz and 400 kHz Clock Compatibility
- Page Write Time 5 ms max.
- Self-Timed Erase/Write Cycle
Pinout:
The 24LC256 EEPROM has the pinout shown in the following pictures:
Pins A0, A1 and A2 select the I2C addresses,
1 | 0 | 1 | 0 | A2 | A1 | A0 | x |
So if you connect pins A0, A1, A2 to GND the I2C address will be 1010000 = 0x50 in hexadecimal.
The WP pin is “write protect”, set this low for read/write or high for read only. We are going to link it to GND.
Pin Vcc will receive the +5V.
Pin Vss is the GND.
SCL and SDA pins are the pins used by the I2C bus.
Interfacing with Arduino
To interface the 24LC256 chip to Arduino I developed a simple board using a stripboard.
It is shown in the following picture:
If you decide to build this board, remeber that the copper tracks shall be on the bottom side so when you cut the tracks you have to mirror the abpove picture.
Now you have to connect, with some wires, your Arduino with this board.
GND <--> GND
DA <--> A4
CL <--> A5
5V <--> 5V
Testing the board
Now let's make some test, the code to do the test is very simple:
#include <Wire.h> // for I2C #define i2caddr 0x50 // device address for left-hand chip on our breadboard byte d=0; // data to store in or read from the EEPROM void setup() { Serial.begin(115200); // Initialize the serial line Wire.begin(); // wake up the I2C Serial.println("Writing data..."); for (int i=0; i<20; i++) { writeData(i,i); } Serial.println("DONE"); Serial.println("Reading data..."); for (int i=0; i<20; i++) { Serial.print(i); Serial.print(" : "); d=readData(i); Serial.println(d, DEC); } Serial.println("DONE"); } // writes a byte of data in memory location addr void writeData(unsigned int addr, byte data) { Wire.beginTransmission(i2caddr); // set the pointer position Wire.write((int)(addr >> 8)); Wire.write((int)(addr & 0xFF)); Wire.write(data); Wire.endTransmission(); delay(10); } // reads a byte of data from memory location addr byte readData(unsigned int addr) { byte result; Wire.beginTransmission(i2caddr); // set the pointer position Wire.write((int)(addr >> 8)); Wire.write((int)(addr & 0xFF)); Wire.endTransmission(); Wire.requestFrom(i2caddr,1); // get the byte of data result = Wire.read(); return result; } void loop() { }
If all is working fine the output on the serial line should be as follows:
Writing data…
DONE
Reading data…
0 : 0
1 : 1
2 : 2
3 : 3
4 : 4
5 : 5
6 : 6
7 : 7
8 : 8
9 : 9
10 : 10
11 : 11
12 : 12
13 : 13
14 : 14
15 : 15
16 : 16
17 : 17
18 : 18
19 : 19
DONE
see you soon,
Gg1
Nice one. I had been struggling with the Arduino Cookbook example of EEPROM Your bit about the A0,A1,A2 i.e. 1010000 explains all – I hadn’t realised (novice) that the bitfield becomes the hex address. The Cookbook is totally wrong unless I’m missing something and the Microchip datasheet doesn’t explain.
Regards (UK oldie)