https://github.com/nopnop2002/esp-idf-24c
Two-Wire Serial EEPROM Access Library for esp-idf
https://github.com/nopnop2002/esp-idf-24c
24c02 24c04 24c08 24c128 24c16 24c256 24c32 24c512 24c64 eeprom esp-idf esp32 i2c two-wire
Last synced: 5 months ago
JSON representation
Two-Wire Serial EEPROM Access Library for esp-idf
- Host: GitHub
- URL: https://github.com/nopnop2002/esp-idf-24c
- Owner: nopnop2002
- License: mit
- Created: 2020-04-14T01:57:49.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2025-04-03T22:05:09.000Z (9 months ago)
- Last Synced: 2025-06-04T12:06:46.717Z (7 months ago)
- Topics: 24c02, 24c04, 24c08, 24c128, 24c16, 24c256, 24c32, 24c512, 24c64, eeprom, esp-idf, esp32, i2c, two-wire
- Language: C
- Homepage:
- Size: 41 KB
- Stars: 20
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# esp-idf-24c
Two-Wire Serial EEPROM Driver for esp-idf.
# Software requirements
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.
# Installation
```
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
```
# Configuration
You have to set this config value with menuconfig.
- CONFIG_MODEL
- CONFIG_SCL_GPIO
- CONFIG_SDA_GPIO
- CONFIG_I2C_ADDRESS



# Memory size
|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.
# API
```
// 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);
```
# Wireing
|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.
Typical circuit.
When A0 A1 A2 is GND, i2c address is 0x50.

# Serial Console
- 24C04

- 24C16

- 24C32

- 24C64

- 24C128

- 24C256

- 24C512

# How to use this component in your project
Create idf_component.yml in the same directory as main.c.
```
YourProject --+-- CMakeLists.txt
+-- main --+-- main.c
+-- CMakeLists.txt
+-- idf_component.yml
```
Contents of idf_component.yml.
```
dependencies:
nopnop2002/at24c:
path: components/at24c/
git: https://github.com/nopnop2002/esp-idf-24c.git
```
When you build a projects esp-idf will automaticly fetch repository to managed_components dir and link with your code.
```
YourProject --+-- CMakeLists.txt
+-- main --+-- main.c
| +-- CMakeLists.txt
| +-- idf_component.yml
+-- managed_components ----- nopnop2002__at24c
```