This is the AT24C256 that provides 32 Kbyte of serial, Electrically Erasable Programmable Read Only Memory (EEPROM) organized at 256Kbits WORDS of 8 BITS each. EEPROM can store data permanently unless you erase or write it and won’t lost the data when power off. Some of microcontroller have limited storage like Arduino it has only 512 bytes data space compare to AT24C256 has 256Kb EEPROM will be very suitable for small amount of data storage or extending data storage for your microcontroller. The 24C256 is optimized for use in minimal storage applications where low-power and low-voltage operation, driven using i2C serial communication bus to help you do much more multiple series of storage.
- Maximum Writing Time: 5 mS
- Read / Write Cycle: 100000
- Data Retention: > 200 Years
- Write Current Consumption: 3mA – 5VDC
- Read Current Consumption: 400uA – 5VDC
- Power Consumption on Standby: 100nA -5VDC
- Temperature Range: -40*C to +125*C
Required Components
- Arduino Microcontroller, Teensy, ESP8266, ATTINY, STM32
- AT24C256 Chip / Module
- Resistors (4k7, 10k, 220 Ohms)
- Capacitor (0.1 uf)
- 3mm LED
- Solder Less Bread Board
- Jumper Wire / DuPont Wire
Wiring Guide for Module
As you can see the diagram above the pin A0, A1, A2 are connected to the ground these pins allow you to customize the device i2C bus address, below the data sheet we that we verify how it is formed the byte address. For more details Please refer to the Datasheet below.
4 significant bits are present for the control code while bits A0, A1, and A2 are customizable. The least significant bit R/W is used to select a WRITE/READ operations, connected to GND PIN A0, A1, A2 fileds CHIP SELECT BITS are 0. See the address of the device below. we get a value of 0x50
To perform WRITING / READING the 24C256 you must submit in addition to CONTROL BYTE which is specifies the device address in i2C Bus, two bytes that indicate the address memory we what to write/read.
Schematics Diagram / Wiring Guide for Single and Multiple EEPROM
The Wire library allows you to pass an integer value so we could just make a bit-wise operation to device the integer variable into two bytes. There are already functions that simplify this operation HIGH BYTE and LOW BYTE. The following code allows you to write all the 32000 bytes of memory.
Source Code 1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
#include <Wire.h> address int = 0; int date = 0; int loop = 0; void setup () { Serial.begin (9600); //Star Serial Communication at baud rate 9600 wait // initialization of the 24C256 while (! Serial) { ; } delay (5000); Serial.println ( "14CORE | 24C256 EEPROM TEST CODE"); // send a message to the serial monitor Serial.println ( "--------------------------------"); Serial.println ( "START... "); // initialize the I2C port of Arduino Wire.begin (); } void loop () { Serial.println ( "14CORE | 24C256 EEPROM"); Serial.println ("-----------------------") Serial.println ("START WRITING"); //Writing to serial address = 0; //Initializing Variable for (loop = 0; loop <32000; loop ++) //Running cyclically writing 32000 memory location { Wire.beginTransmission (0x50); //Start sending control byte specifying write request memory location Wire.write (high byte (address)); //Sending 2 byte containing address Wire.write (low byte (address)); //Sending 2 byte containing address Wire.write (bytes (data)); // Writing byte in memory location previously selected Wire.endTransmission (); //Ending Transmission data ++; //Start value of data increment if (data == 255) //If data variable reaches to 256 reset its value to 0 data = 0; Address ++; //Start increment address value delay (5); // Wait 5 miliseconds to end the operation writing to memory } Serial.println ( "WRITING END"); delay (500); //Delayed to 1/2 second Serial.println ( "START SENDING"); address = 0; for (loop = 0; loop <32000; loop ++) { Wire.beginTransmission (0x50); //Send control byte specifying write request to 0x50 memory Wire.write (high byte (address)); Wire.write (low byte (address)); Wire.endTransmission (); address ++; //Start increment address value Wire.requestFrom (0x50, 1); // start request byte at 0x50 while (Wire.available ()) { Serial.print (cycle); Serial.print ( ":"); bytes Wire.read c = (); Serial.println (c); // Sendind the data to the serial monitor } } delay (1000); } |
Source Code 2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
#include <Wire.h> #include "AT24C256.h" //Include AT24C256 Code Libraries AT24C256 g_eeprom(0x50); //Start code 0x50 Address void printContents() { int eeaddress = 0; byte value; while (true) { value = g_eeprom.read(eeaddress++); if ((value == 0xFF) || (eeaddress == 32768)) { Serial.println(); break; } Serial.print((char)value); } } void setup() { Serial.begin(9600); Serial.println ( "14CORE | 24C256 EEPROM TEST CODE"); // send a message to the serial monitor Serial.println ( "--------------------------------"); Serial.println ( "START... "); Wire.begin(); printContents(); } void loop() { while (Serial.available()) { int i, m; String data = Serial.readStringUntil('\n'); for (i = 0, m = data.length(); i < m; ++i) { g_eeprom.write(i, data[i]); Serial.println("14CORE | AT24C256 WRITE CODE TEST"); Serial.println("---------------------------------") Serial.println("Writing : "); Serial.print(data[i]); Serial.println(" IN : "); Serial.println(i); } g_eeprom.write(i, 0xFF); //Start write printContents(); } delay(1); } |
Writing 32000 bytes will take a few minutes to write because the code takes about 5 millisecond to write a byte 32000 x 0005 = > 160 Seconds. The serial reading is more fluid and influenced by the speed of the serial communication which is running to 9600 bytes per second.
Downloads
Heads up, the datasheet link is not quite right.
Try http://ww1.microchip.com/downloads/en/devicedoc/doc0670.pdf
I can not get this code to run as written lots of typo errors, I believe.
Is the diagram on image 24C256-EEPROM-Wiring-Diagram-Schematics-Manual-Guide-14core.jpg correct? The sda and scl of leftmost memory ic is hooked to vcc. The 4.7k pull up resistors should be placed vertically to the vcc line.
Thanks,