AT24Cxxx I2C EEPROM and FRAM (incl. M24M02, MB85RCxx, FT24Cxxx, 24LCxxx, CAT24Cxxx, BR24Gxxx)
Overview
The AT24 (About Modules) module interfaces to an I2C EEPROM of capacity from 1kbit to 4mbit - almost all I2C non-volatile memory chips in that capacity range uses the same protocol. The table below shows the Atmel part numbers that this module should be compatible with, and the appropriate parameters for them. There are also pin compatible EEPROMs available from many other manufacturers, including the FT24Cxxx (Fremont Micro Devices), 24LCxxx (Microchip), CAT24Cxxx (ON Semi), BR24Gxxx (Rohm) (in all cases, the xxx is the size of the part, in kbits). Parts are available in DIP-8, SOP-8, and even SOT-23-5 (for lower capacities). All of these parts should work equally well with this module. This module can also be used with I2C FRAM devices like the MB85RCxx parts.
Examples (using the Atmel naming)
Part | Size (kbit) | Size (kbyte) | Page size |
---|---|---|---|
AT24C01 | 1 | 128 Bytes | 8 bytes |
AT24C32 | 32 | 4 KBytes | 32 bytes |
AT24C64 | 64 | 8 KBytes | 32 bytes |
AT24C128 | 128 | 16 KBytes | 64 bytes |
AT24C256 | 256 | 32 KBytes | 64 bytes |
AT24C512 | 512 | 64 KBytes | 128 bytes |
M24M02 | 2048 | 256 kBytes | 256 bytes |
MB85RC04 | 4 | 512 Bytes | 0 (FRAM) |
The I2C address of these devices is set by the three address pins on the EEPROM. This allows you to have up to eight eeproms connected to a single I2C bus. However, note that some EEPROM's do not support all of these address pins. Additionally, certain sizes use these address bits as the MSBs of address, and thus they are not available for addressing multiple parts:
Size | A2 | A1 | A0 |
---|---|---|---|
4 kbit | Y | Y | N |
8 kbit | Y | N | N |
16 kbit | N | N | N |
1 mbit | Y | Y | N |
2 mbit | Y | N | N |
4 mbit | N | N | N |
Wiring
If using one of the ubiquitous and inexpensive EEPROM breakout boards, just connect VCC to +3.3v, GND to GND, and SCL and SDA to the respective pins on the Espruino. The address bits can be set using the jumpers.
If working with a bare chip, you will also need to include the two 10k ohm pullup resistors between +3.3v and SCL and SDA. The address pins should be connected either to ground (for a 0) or +3.3v (for a 1). A chip in 8-pin SOIC package can be soldered into the prototyping area on the Espruino board.
Setup
Setup I2C, then call:
var eeprom=require("AT24").connect(i2c, pagesize, capacity, i2caddress)
i2c
is the i2c bus.
pagesize
is the page size for page writes.
capacity
is the eeprom capacity, in kbits.
i2caddress
is the value of the address pins. 0-3 or 0-7, depending on the part.
Reading and Writing
These support the same interface as the SPI (AT25) and OneWire EEPROM modules
eeprom.read(address,bytes,asStr)
read()
reads the specified number of bytes, starting at the specified address.
eeprom.write(address,data)
write()
writes the supplied data to the specified address. The data can be a string or an array of bytes. Address may be undefined, in this case, it will read from where last read ended. This handles breaking the write up into pages, and waiting for the write delay period. The write delay is 10ms per page (This means that large writes can be quite slow). There is no delay when pagesize is 0 (for FRAM);
This page is auto-generated from GitHub. If you see any mistakes or have suggestions, please let us know.