Skip to content

About

Esp-idf component for 24C32/24C64 2-wire serial EEPROM ICs

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

esp32-24C32

This is an esp-idf component library for interfacing with the 4KB/8KB 24C32/24C64 I²C EEPROM ICs. These ICs are commonly found on DS3231 rtc timer boards.

DS3231_board

Usage

Initializing

AT24C32 (ICs with a size of 32Kb and 32 Byte page cache)

EEPROM24CX eeprom = EEPROM24CX();

eeprom.begin(
    0x57, 		// I2C device address
    GPIO_NUM_7, // SCL pin
    GPIO_NUM_6, // SDA pin
    -1			// I2C port number (-1 = auto)
);

IC's with other EEPROM and page cache sizes (e.g. AT24C64, 24C32)

// Example for an AT24C64 which has an 8K EEPROM size and 32 bytes page cache

EEPROM24CX eeprom = EEPROM24CX();

eeprom.begin(
    0x57, 		// I2C device address
    GPIO_NUM_7, // SCL pin
    GPIO_NUM_6, // SDA pin
    8192,		// EEPROM size in bytes
    32,			// Page cache size in bytes
    -1			// I2C port number (-1 = auto)
);

Writing to the eeprom

To write data to the eeprom, use the write function:

uint8_t data[5] = {0, 1, 2, 3, 4};

eeprom.write(
    0, 			 // Address to write at
    data, 		 // Data buffer
    sizeof(data) // Data buffer length
);

Random read (reading at a specific address)

To read data at a specific address, use the read_random function:

uint8_t rx_buffer[5];

eeprom.read_random(
    0,				  // Address to read from
    rx_buffer,		  // Data buffer
    sizeof(rx_buffer) // Data buffer length
);

Sequential read (reading at the current address pointer)

The sequential read operation reads data from the IC's current address pointer.

uint8_t rx_buffer[5];

eeprom.read_sequential(
    rx_buffer,		  // Data buffer
    sizeof(rx_buffer) // Data buffer length
);

Note: Calling read_sequential before either write or read_random can lead to unexpected results due to the current address pointer value of the EEPROM IC being unknown. This happens because the EEPROM has no way of communicating its address pointer to the I²C master, so to reliably determine its value, a read or write operation at a specific address has to be executed first, after which the EEPROM's address pointer has the value of the last byte written to/read from.

If read_sequential is called and the EEPROM's address pointer is undetermined, the library assumes it to be 0 and logs a warning. For more details, see the code docs for EEPROM24CX::get_eeprom_address_pointer.

Addressing

The 24C32 uses a classic 7 bit I²C address starting with the fixed bits 1010. The remaining 3 bits are determined by the IC's three addressing pins A2, A1 and A0.
This means up to 8 IC's can be connected on the same I²C bus, with their addresses ranging from 0x50 to 0x57.

Address format: 1 0 1 0 <A2> <A1> <A0>

Pin connected to GND or floating: 0
Pin connected to VCC: 1

Example:

  • All pins floating/GND: 0b1010000 = 0x50
  • All pins VCC: 0b1010111 = 0x57

On DS3231 rtc module boards, these pins are usually connected to VCC by default with an optional solder bridge connecting them to GND, meaning the default address of the 24C32 on those boards is almost always 0x57.

A note about 24C32 hardware revisions

The 24C32 was originally developed by Atmel as the AT24C32 and AT24C64 respectively. Atmel was later acquired by Microchip Technology which continued to produce the 24C32 (later 24LC32) with some differences in hardware design. Microchip's 24C32 and 24LC32 are now considered obsolete and have been replaced by the 24LC32A/24LC65.

IC Manufacturer EEPROM Size Page cache size Endurance
AT24C32 Atmel 32K bits (4096 bytes) 32 bytes ~1,000,000 write cycles
AT24C64 Atmel 64K bits (8192 bytes) 32 bytes ~1,000,000 write cycles
24C32 Microchip Technology 32K bits (4096 bytes) 64 bytes ~10,000,000 write cycles (first 512 bytes)
~1,000,000 write cycles (remaining 3584 bytes)

Most notably, Microchip's 24C32 features a 4096 bit high endurance block for frequent write operations and a bigger page cache. However, it should be noted that generic clones of the 24C32 family often lack these features.

About

Esp-idf component for 24C32/24C64 2-wire serial EEPROM ICs

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages