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.
Fork of I2CEeprom by
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_inst The I2C bus instance. Pass a reference. address The 8bit I2C address of the chip in the range 0xA0 - 0xAE. pageSize The size of the page used in writing to the chip. chipSize The size of the memory in the chip to allow range checkng. Set to 0 to disable checks. busSpeed The 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:
-
address Starting address to write to. value Value 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:
-
address Start address for reading memory. value Object 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:
-
address Memory address to start reading from. buffer Pointer to buffer to hold bytes read from memory. size Number 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:
-
address Memory address to read from. value Variable 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:
-
address Memory address to write to. value Value 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:
-
address Memory address to start writting to. buffer Pointer to buffer holding the bytes to write to memory. size Number 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:
-
address Start address to write to memory.
- Returns:
- Number of bytes written to memory.
Definition at line 80 of file I2CEeprom.h.
Generated on Wed Jul 20 2022 22:26:41 by 1.7.2