ArduinoLibs
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Public Member Functions | List of all members
EEPROM24 Class Reference

Reading and writing EEPROM's from the 24LCXX family. More...

#include <EEPROM24.h>

Public Member Functions

 EEPROM24 (I2CMaster &bus, unsigned long type, uint8_t bank=0)
 Constructs a new EEPROM access object on bus for an EEPROM of the specified type. More...
 
unsigned long size () const
 Returns the size of the EEPROM in bytes. More...
 
unsigned long pageSize () const
 Returns the size of a single EEPROM page in bytes. More...
 
bool available ()
 Returns true if the EEPROM is available on the I2C bus; false otherwise. More...
 
uint8_t read (unsigned long address)
 Reads a single byte from the EEPROM at address. More...
 
size_t read (unsigned long address, void *data, size_t length)
 Reads a block of length bytes from the EEPROM at address into the specified data buffer. More...
 
bool write (unsigned long address, uint8_t value)
 Writes a byte value to address in the EEPROM. More...
 
size_t write (unsigned long address, const void *data, size_t length)
 Writes length bytes from a data buffer to address in the EEPROM. More...
 

Detailed Description

Reading and writing EEPROM's from the 24LCXX family.

The 24LCXX family of EEPROM's provide a variety of memory sizes from 16 bytes up to 128 kBytes that can be accessed via the I2C protocol. These chips can be used to augment the 1 kByte or so of builtin EEPROM memory that is typical on Arduino boards. The EEPROM should be wired to an Arduino Uno as follows:

eeprom_circuit.png

Access to a 24LCXX chip is initialized as follows:

SoftI2C i2c(A4, A5);
EEPROM24 eeprom(i2c, EEPROM_24LC256);

Once initialized, read() and write() can be used to manipulate the contents of the EEPROM's memory.

The following EEPROM types are supported by this class:

ChipTypeSize
24lc00EEPROM_24LC00 16 bytes
24lc01EEPROM_24LC01 128 bytes
24lc014EEPROM_24LC014 128 bytes
24lc02EEPROM_24LC02 256 bytes
24lc024EEPROM_24LC024 256 bytes
24lc025EEPROM_24LC025 256 bytes
24lc04EEPROM_24LC04 512 bytes
24lc08EEPROM_24LC08 1 kByte
24lc16EEPROM_24LC16 2 kBytes
24lc32EEPROM_24LC32 4 kBytes
24lc64EEPROM_24LC64 8 kBytes
24lc128EEPROM_24LC128 16 kBytes
24lc256EEPROM_24LC256 32 kBytes
24lc512EEPROM_24LC512 64 kBytes
24lc1025EEPROM_24LC1025 128 kBytes
24lc1026EEPROM_24LC1026 128 kBytes

There can be multiple 24LCXX chips on the same I2C bus, as long as their A0, A1, and A2 address pins are set to different values. For example, two 24LC256 chips can be used to provide the same memory capacity as a single 24LC512 chip. The optional bank parameter to the constructor is used to assign different bank addresses to each chip:

SoftI2C i2c(A4, A5);
EEPROM24 eeprom0(i2c, EEPROM_24LC256, 0);
EEPROM24 eeprom1(i2c, EEPROM_24LC256, 1);
See Also
I2CMaster

Definition at line 60 of file EEPROM24.h.

Constructor & Destructor Documentation

EEPROM24::EEPROM24 ( I2CMaster bus,
unsigned long  type,
uint8_t  bank = 0 
)

Constructs a new EEPROM access object on bus for an EEPROM of the specified type.

The bank can be used to choose between multiple EEPROM's on bus of the specified type. The bank corresponds to the value that is set on the EEPROM's A0, A1, and A2 address pins. Note that some EEPROM's have less than 3 address pins; consult the datasheet for more information.

Definition at line 95 of file EEPROM24.cpp.

Member Function Documentation

bool EEPROM24::available ( )

Returns true if the EEPROM is available on the I2C bus; false otherwise.

This function can be used to probe the I2C bus to determine if the EEPROM is present or not.

See Also
read(), write()

Definition at line 152 of file EEPROM24.cpp.

unsigned long EEPROM24::pageSize ( ) const
inline

Returns the size of a single EEPROM page in bytes.

Writes that are a multiple of the page size and aligned on a page boundary will typically be more efficient than non-aligned writes.

See Also
size()

Definition at line 66 of file EEPROM24.h.

uint8_t EEPROM24::read ( unsigned long  address)

Reads a single byte from the EEPROM at address.

See Also
write()

Definition at line 167 of file EEPROM24.cpp.

size_t EEPROM24::read ( unsigned long  address,
void *  data,
size_t  length 
)

Reads a block of length bytes from the EEPROM at address into the specified data buffer.

Returns the number of bytes that were read, which may be short if address + length is greater than size() or the EEPROM is not available on the I2C bus.

See Also
write(), available()

Definition at line 187 of file EEPROM24.cpp.

unsigned long EEPROM24::size ( ) const
inline

Returns the size of the EEPROM in bytes.

See Also
pageSize()

Definition at line 65 of file EEPROM24.h.

bool EEPROM24::write ( unsigned long  address,
uint8_t  value 
)

Writes a byte value to address in the EEPROM.

Returns true if the byte was written successfully, or false if address is out of range or the EEPROM is not available on the I2C bus.

See Also
read(), available()

Definition at line 213 of file EEPROM24.cpp.

size_t EEPROM24::write ( unsigned long  address,
const void *  data,
size_t  length 
)

Writes length bytes from a data buffer to address in the EEPROM.

Returns the number of bytes that were written, which may be short if address + length is greater than size() or the EEPROM is not available on the I2C bus.

Best performance will be achieved if address and length are a multiple of pageSize().

See Also
read(), available(), pageSize()

Definition at line 235 of file EEPROM24.cpp.


The documentation for this class was generated from the following files: