The AT24C256 External EEPROM by Hiletgo is a non-volatile memory chip that uses the I2C (Inter-Integrated Circuit) protocol for communication. With a storage capacity of 256 kilobits (32 kilobytes), it is ideal for applications that require data retention after power-off, such as storing configuration settings, calibration data, or user preferences. Common use cases include embedded systems, consumer electronics, and IoT devices.
Pin Number | Pin Name | Description |
---|---|---|
1 | A0 | Address pin 0 (configurable) |
2 | A1 | Address pin 1 (configurable) |
3 | A2 | Address pin 2 (configurable) |
4 | GND | Ground |
5 | SDA | Serial Data Line |
6 | SCL | Serial Clock Line |
7 | WP | Write Protect (active high) |
8 | Vcc | Supply Voltage |
#include <Wire.h>
// AT24C256 I2C address is 0x50 if all address pins (A0, A1, A2) are connected to GND
#define EEPROM_I2C_ADDRESS 0x50
void setup() {
Wire.begin(); // Initialize I2C
Serial.begin(9600); // Start serial communication at 9600 baud
}
void loop() {
unsigned int address = 0; // EEPROM memory address
byte dataToWrite = 45; // Data to write to EEPROM
// Write data to EEPROM
writeToEEPROM(address, dataToWrite);
delay(10); // Short delay to ensure the write process is completed
// Read data from EEPROM
byte dataRead = readFromEEPROM(address);
Serial.print("Data read from EEPROM: ");
Serial.println(dataRead);
delay(2000); // Wait for 2 seconds before next read/write
}
void writeToEEPROM(unsigned int address, byte data) {
Wire.beginTransmission(EEPROM_I2C_ADDRESS);
Wire.write((int)(address >> 8)); // MSB
Wire.write((int)(address & 0xFF)); // LSB
Wire.write(data);
Wire.endTransmission();
delay(5); // EEPROM write cycle time (max 5ms)
}
byte readFromEEPROM(unsigned int address) {
byte data = 0xFF; // Data read from EEPROM
Wire.beginTransmission(EEPROM_I2C_ADDRESS);
Wire.write((int)(address >> 8)); // MSB
Wire.write((int)(address & 0xFF)); // LSB
Wire.endTransmission();
Wire.requestFrom(EEPROM_I2C_ADDRESS, 1);
if (Wire.available()) data = Wire.read();
return data;
}
Q: How do I set the I2C address for the AT24C256? A: The I2C address is determined by the state of the A0, A1, and A2 pins. Connect these pins to GND or Vcc to set the address.
Q: Can I connect multiple AT24C256 devices on the same I2C bus? A: Yes, you can connect up to 8 devices by configuring the A0, A1, and A2 pins with different combinations.
Q: What is the purpose of the WP pin? A: The WP (Write Protect) pin is used to prevent accidental writes to the EEPROM. When connected to Vcc, the device is write-protected.
For further assistance, consult the manufacturer's datasheet and application notes.