libpropeller
Making PropellerGCC Easier
 All Classes Files Functions Variables Enumerations Enumerator Macros Pages
Public Member Functions | List of all members
EEPROM Class Reference

Access I2C EEPROMs. More...

#include <eeprom.h>

Public Member Functions

void Init (const int scl=28, const int sda=29)
 Initialize an EEPROM instance. More...
 
bool Put (const unsigned short address, const char byte)
 Put a byte into the EEPROM. More...
 
bool Put (unsigned short address, char bytes[], int size)
 Write a block of data to the EEPROM. More...
 
bool PutNumber (const unsigned short address, const int bytes, const int length)
 Write up to 4 bytes to a memory location. More...
 
int Get (unsigned short address)
 Get a single byte from the EEPROM. More...
 
int Get (unsigned short address, char bytes[], const int length)
 Get a block of bytes from the EEPROM. More...
 
int GetNumber (unsigned short address, int length)
 Get up to 4 bytes from the EEPROM and concatenate them into a single int. More...
 

Detailed Description

Access I2C EEPROMs.

Valid EEPROM data addresses are in the range 0 to 0xFFFF for 64KB EEPROMS, and 0 to 0x7FFF for 32KB EEPROMs.

Warning
Requires that the A0, A1, and A2 pins of the EEPROM to be tied to ground.

This driver was written to work with the AT24C512C EEPROM from Atmel, but it may work with other I2C EEPROMs.

Member Function Documentation

int EEPROM::Get ( unsigned short  address)
inline

Get a single byte from the EEPROM.

Parameters
addressthe two byte address to read from.
Returns
the byte read on success, or -1 on timeout or other failure.
int EEPROM::Get ( unsigned short  address,
char  bytes[],
const int  length 
)
inline

Get a block of bytes from the EEPROM.

Note: This function takes care of the page reads from the EEPROM.

Parameters
addressthe two byte address to read from.
bytesthe memory location to store the data.
lengththe number of bytes to read.
Returns
0 on success, or -1 on timeout or other failure.

Here is the call graph for this function:

int EEPROM::GetNumber ( unsigned short  address,
int  length 
)
inline

Get up to 4 bytes from the EEPROM and concatenate them into a single int.

This function is useful for retrieving an integer or a short stored in EEPROM. Bytes must be stored in little endian order in the EEPROM.

Parameters
addressthe two byte address to read from.
lengththe number of bytes to read.
Returns
the number read from the EEPROM. If length is < 4, then the upper bytes are set to 0.

Here is the call graph for this function:

void EEPROM::Init ( const int  scl = 28,
const int  sda = 29 
)
inline

Initialize an EEPROM instance.

Does not require a cog.

Todo:
(SRLM): Does this class interfere with other I2C drivers?
Parameters
sclThe I2C SCL pin. Defaults to the Propeller default SCL pin.
sdaThe I2C SDA pin. Defaults to the Propeller default SDA pin.

Here is the call graph for this function:

bool EEPROM::Put ( const unsigned short  address,
const char  byte 
)
inline

Put a byte into the EEPROM.

Parameters
addressthe two byte address to write to.
bytethe single byte of data to write
Returns
success or failure
bool EEPROM::Put ( unsigned short  address,
char  bytes[],
int  size 
)
inline

Write a block of data to the EEPROM.

There are no restrictions on page alignment.

For optimal efficiency, the data should be aligned in 128 byte blocks starting with an address whose lowest 7 bits are 0000000. The is a slight (one time) performance cost to not aligning the data this way.

Parameters
addressthe two byte address to write to.
bytes[]the array of bytes to write.
sizethe number of bytes to write.
Returns
success or failure

Here is the call graph for this function:

bool EEPROM::PutNumber ( const unsigned short  address,
const int  bytes,
const int  length 
)
inline

Write up to 4 bytes to a memory location.

Stores them in little endian order.

This function is useful for storing an int (long, 4 bytes) of data to the EEPROM. It can also be used to store a short (word, 2 bytes).

Parameters
addressthe two byte address to write to.
bytesthe set of bytes to store. If length is less than 4, Put stores the bytes beginning with the LSB.
lengththe number of bytes to store, up to 4.
Returns
success or failure

Here is the call graph for this function:


The documentation for this class was generated from the following file: