ArduinoLibs
|
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... | |
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:
Access to a 24LCXX chip is initialized as follows:
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:
Chip | Type | Size |
24lc00 | EEPROM_24LC00 | 16 bytes |
24lc01 | EEPROM_24LC01 | 128 bytes |
24lc014 | EEPROM_24LC014 | 128 bytes |
24lc02 | EEPROM_24LC02 | 256 bytes |
24lc024 | EEPROM_24LC024 | 256 bytes |
24lc025 | EEPROM_24LC025 | 256 bytes |
24lc04 | EEPROM_24LC04 | 512 bytes |
24lc08 | EEPROM_24LC08 | 1 kByte |
24lc16 | EEPROM_24LC16 | 2 kBytes |
24lc32 | EEPROM_24LC32 | 4 kBytes |
24lc64 | EEPROM_24LC64 | 8 kBytes |
24lc128 | EEPROM_24LC128 | 16 kBytes |
24lc256 | EEPROM_24LC256 | 32 kBytes |
24lc512 | EEPROM_24LC512 | 64 kBytes |
24lc1025 | EEPROM_24LC1025 | 128 kBytes |
24lc1026 | EEPROM_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:
Definition at line 60 of file EEPROM24.h.
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.
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.
Definition at line 152 of file EEPROM24.cpp.
|
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.
Definition at line 66 of file EEPROM24.h.
uint8_t EEPROM24::read | ( | unsigned long | address | ) |
Reads a single byte from the EEPROM at address.
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.
Definition at line 187 of file EEPROM24.cpp.
|
inline |
Returns the size of the EEPROM in bytes.
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.
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().
Definition at line 235 of file EEPROM24.cpp.