Two-Wire Serial EEPROM Driver for esp-idf.
ESP-IDF V4.4/V5.x.
ESP-IDF V5.0 is required when using ESP32-C2.
ESP-IDF V5.1 is required when using ESP32-C6.
Note for ESP-IDF V5.2.
A new i2c driver is now available in ESP-IDF V5.2.
Under ESP-IDF V5.2 or later, this project uses a new i2c driver.
git clone https://github.com/nopnop2002/esp-idf-24c
cd esp-idf-24c
idf.py set-target {esp32/esp32s2/esp32s3/esp32c2/esp32c3/esp32c6}
idf.py menuconfig
idf.py flash
You have to set this config value with menuconfig.
- CONFIG_MODEL
- CONFIG_SCL_GPIO
- CONFIG_SDA_GPIO
- CONFIG_I2C_ADDRESS
Device | Number of Bits | Address range | i2c address |
---|---|---|---|
24C02 | 2K | 0x00-0xFF | 0x50-0x57 |
24C04 | 4K | 0x00-0x1FF | 0x50/0x52/0x54/0x56(*1) |
24C08 | 8K | 0x00-0x3FF | 0x50/0x54(*2) |
24C16 | 16K | 0x00-0x7FF | 0x50(*3) |
24C32 | 32K | 0x00-0xFFF | 0x50-0x57 |
24C64 | 64K | 0x00-0x1FFF | 0x50-0x57 |
24C128 | 128K | 0x00-0x3FFF | 0x50-0x53 |
24C256 | 256K | 0x00-0x7FFF | 0x50-0x53 |
24C512 | 512K | 0x00-0xFFFF | 0x50-0x53 |
(*1) Two consecutive i2c entries are used in the library.
(*2) Four consecutive i2c entries are used in the library.
(*3) Eight consecutive i2c entries are used in the library.
// Open device
// i2c_port:I2C_NUM_0/I2C_NUM_1
esp_err_t InitRom(EEPROM_t * dev, i2c_port_t i2c_port);
// Get EEPROM maximum address
uint16_t MaxAddress(EEPROM_t * dev);
// Read data from EEPROM
// data_addr:read address
// data:read data buffer
esp_err_t ReadRom(EEPROM_t * dev, uint16_t data_addr, uint8_t * data);
// Write data to EEPROM
// data_addr:write address
// data:write data buffer
esp_err_t WriteRom(EEPROM_t * dev, uint16_t data_addr, uint8_t data);
24Cxx | ESP32 | ESP32-S2/S3 | ESP32-C2/C3/C6 | ||
---|---|---|---|---|---|
A0 | -- | GND | GND | GND | (*1) |
A1 | -- | GND | GND | GND | (*1) |
A2 | -- | GND | GND | GND | (*1) |
GND | -- | GND | GND | GND | |
SDA | -- | GPIO21 | GPIO11 | GPIO4 | (*2) |
SCL | -- | GPIO22 | GPIO12 | GPIO5 | (*2) |
WP | -- | GND | GND | GND | |
VCC | -- | 3.3V | 3.3V | 3.3V |
(*1) I2C Address selection. See data sheet.
(*2) You can change any GPIO using menuconfig.