M24LC256 v1
Public Member Functions | Protected Attributes

M24LC256 Class Reference

Driver for Microchip 24LC256 EEPROM. More...

#include <M24LC256.h>

List of all members.

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.

Detailed Description

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!

Examples:

readwrite.pde.


Constructor & Destructor Documentation

M24LC256::M24LC256 ( uint8_t  _address)

Constructor.

Parameters:
_addressthe low 3 bits of the address for the chip being addressed. This should correspond to the A0-A2 pins.

Member Function Documentation

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.

Warning:
This will not read beyond the top of the address space of the chip. (0x8000). If you attempt to read beyond the upper limit, only the amount found before the memory limit is read. Check the return value for actual number of bytes read.
Parameters:
locationThe chip address where to read the data
bufThe in-memory location of where to place the data
lenThe maximum number of bytes desired to be read
Returns:
The number of bytes read from the chip
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.

Parameters:
locationThe chip address where to read the data
lengthThe maximum number of bytes desired to be read
dataThe in-memory location of where to place the data
Returns:
The number of bytes read from the chip
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.

Warning:
This will not write beyond the top of the address space of the chip. (0x8000). If you attempt to write beyond the upper limit, only the amount which fits within the memory limit is written, the rest is ignored.
Parameters:
locationThe chip address where to write the data
bufThe in-memory location of where to look for the data
lenThe 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.

Parameters:
locationThe chip address where to write the data
lengthThe number of bytes available to be written
dataThe in-memory location to find the data
Returns:
The number of bytes written to the chip

The documentation for this class was generated from the following file:
 All Classes Functions Variables