M24LC256 v1
|
Driver for Microchip 24LC256 EEPROM. More...
#include <M24LC256.h>
Public Member Functions | |
M24LC256 (uint8_t _address) | |
Constructor. | |
void | begin (void) |
Setup & prepare. | |
void | write (uint16_t location, void *buf, uint16_t len) |
Write data to any location on the chip. | |
uint16_t | read (uint16_t location, void *buf, uint16_t len) |
Read data from any location on the chip. | |
Protected Member Functions | |
Internals | |
Protected methods that address the chip directly. | |
uint16_t | WriteChunk (uint16_t location, uint16_t length, uint8_t *data) |
Writes a small chunk of data directly to the chip. | |
uint16_t | ReadChunk (uint16_t location, uint16_t length, uint8_t *data) |
Reads a small chunk of data directly from the chip. | |
Protected Attributes | |
uint8_t | i2c_address |
The 7-bit address of the particular device we're driving on the I2C bus. |
Driver for Microchip 24LC256 EEPROM.
Create one instance of this class for each chip in your circuit. This allows you to have up to 8 of these active at any time.
This class is optimized to take advantage of the page size of the chip. The chip has a 5msec write cycle now matter how many bytes you push it, up to its page size (64 bytes for 24LC256. To get higher throughput, increase the size of the Wire buffer by increasing BUFFER_LENGTH in Wire.h and TWI_BUFFER_LENGTH in utility/twi.h. Increase them to 34 for 32-byte writes, and to 66 for 64-byte writes. Be warned that these buffers suck up your memory, so be careful!
M24LC256::M24LC256 | ( | uint8_t | _address | ) |
Constructor.
_address | the low 3 bits of the address for the chip being addressed. This should correspond to the A0-A2 pins. |
void M24LC256::begin | ( | void | ) |
Setup & prepare.
Call this function from within the setup() function of your sketch, AFTER Wire.begin().
Note that this function currently does nothing, but is included for forward compatability. Someday something may be needed here.
uint16_t M24LC256::read | ( | uint16_t | location, |
void * | buf, | ||
uint16_t | len | ||
) |
Read data from any location on the chip.
This function is not constrained by the size or location of data. Write what you want, where you want.
location | The chip address where to read the data |
buf | The in-memory location of where to place the data |
len | The maximum number of bytes desired to be read |
uint16_t M24LC256::ReadChunk | ( | uint16_t | location, |
uint16_t | length, | ||
uint8_t * | data | ||
) | [protected] |
Reads a small chunk of data directly from the chip.
Only 16 bytes maximum are read at a time. Less bytes are read if location
is not on an even 16-byte boundary.
location | The chip address where to read the data |
length | The maximum number of bytes desired to be read |
data | The in-memory location of where to place the data |
void M24LC256::write | ( | uint16_t | location, |
void * | buf, | ||
uint16_t | len | ||
) |
Write data to any location on the chip.
This function is not constrained by the size or location of data. Write what you want, where you want.
location | The chip address where to write the data |
buf | The in-memory location of where to look for the data |
len | The number of bytes to be written |
uint16_t M24LC256::WriteChunk | ( | uint16_t | location, |
uint16_t | length, | ||
uint8_t * | data | ||
) | [protected] |
Writes a small chunk of data directly to the chip.
Only 16 bytes maximum are written at a time. Less bytes are written if location
is not on an even 16-byte boundary.
location | The chip address where to write the data |
length | The number of bytes available to be written |
data | The in-memory location to find the data |