Class to provide simple access to I2C EEPROM chiles like Microchip's 24LC range or AMTELS AT24C range. Chips up to 64Kb in size are directly supported.

Dependents:   Nucleo_praktyki

Fork of I2CEeprom by Robin Hourahane

Embed: (wiki syntax)

« Back to documentation index

I2CEeprom Class Reference

I2CEeprom Class Reference

Class to provide simple access to I2C EEPROM chiles like Microchip's 24LC range or AMTELS AT24C range. More...

#include <I2CEeprom.h>

Public Member Functions

 I2CEeprom (I2C *i2c_inst, int address, size_t pageSize, size_t chipSize, int busSpeed=400000)
 Constructor to create a new instance of the class.
size_t read (size_t address, char &value)
 Read a single byte from the address in memory.
size_t read (size_t address, char *buffer, size_t size)
 Read multiple bytes starting from the address in memory.
template<typename T >
size_t read (size_t address, T &value)
 Read either an instance or an array of a POD type from memory.
size_t write (size_t address, char value)
 Write a single byte to the address in memory.
size_t write (size_t address, const char *buffer, size_t size)
 Write multiple bytes starting from the address in memory.
template<typename T >
size_t write (size_t address, const T &value)
 Write either an instance or an array of a POD type to memory.
size_t fill (size_t address, char value, size_t size)
 Fill a range of memory with a single value.

Detailed Description

Class to provide simple access to I2C EEPROM chiles like Microchip's 24LC range or AMTELS AT24C range.

Chips up to 64Kb in size are directly supported. The class handles multiple page writes so any amount of data can be written in a single call to write. The writes are not buffered so additional memory use is kept to a minimum.

Although not tested it should work with the MAC versions of Microchip range as well but the chipSize will need to be set to include the ROM area as well.

Definition at line 30 of file I2CEeprom.h.


Constructor & Destructor Documentation

I2CEeprom ( I2C *  i2c_inst,
int  address,
size_t  pageSize,
size_t  chipSize,
int  busSpeed = 400000 
)

Constructor to create a new instance of the class.

Parameters:
i2c_instThe I2C bus instance. Pass a reference.
addressThe 8bit I2C address of the chip in the range 0xA0 - 0xAE.
pageSizeThe size of the page used in writing to the chip.
chipSizeThe size of the memory in the chip to allow range checkng. Set to 0 to disable checks.
busSpeedThe frequency of the I2C bus defaults to 400K.

Definition at line 18 of file I2CEeprom.cpp.


Member Function Documentation

size_t fill ( size_t  address,
char  value,
size_t  size 
)

Fill a range of memory with a single value.

No memory is allocated so large areas can be filled with minimal memory usage.

Parameters:
addressStarting address to write to.
valueValue to be written to memory. size Number of bytes to be written.
Returns:
Number of bytes written to memory.

Definition at line 131 of file I2CEeprom.cpp.

size_t read ( size_t  address,
T &  value 
)

Read either an instance or an array of a POD type from memory.

Note the value of the type can't contain pointers.

Parameters:
addressStart address for reading memory.
valueObject to be read from memory.
Returns:
Number of bytes read from memory.

Definition at line 59 of file I2CEeprom.h.

size_t read ( size_t  address,
char *  buffer,
size_t  size 
)

Read multiple bytes starting from the address in memory.

Parameters:
addressMemory address to start reading from.
bufferPointer to buffer to hold bytes read from memory.
sizeNumber of bytes to be read from memory.
Returns:
Number of bytes read from memory.

Definition at line 42 of file I2CEeprom.cpp.

size_t read ( size_t  address,
char &  value 
)

Read a single byte from the address in memory.

Parameters:
addressMemory address to read from.
valueVariable to receive value read.
Returns:
Number of bytes read from memory.

Definition at line 27 of file I2CEeprom.cpp.

size_t write ( size_t  address,
char  value 
)

Write a single byte to the address in memory.

Parameters:
addressMemory address to write to.
valueValue to be written to memory.
Returns:
Number of bytes written to memory.

Definition at line 57 of file I2CEeprom.cpp.

size_t write ( size_t  address,
const char *  buffer,
size_t  size 
)

Write multiple bytes starting from the address in memory.

Parameters:
addressMemory address to start writting to.
bufferPointer to buffer holding the bytes to write to memory.
sizeNumber of bytes to be written to memory.
Returns:
Number of bytes written to memory.

Definition at line 72 of file I2CEeprom.cpp.

size_t write ( size_t  address,
const T &  value 
)

Write either an instance or an array of a POD type to memory.

Note the value of the type can't contain pointers.

Parameters:
addressStart address to write to memory.
Returns:
Number of bytes written to memory.

Definition at line 80 of file I2CEeprom.h.