Access I2C EEPROMs.
More...
#include <eeprom.h>
|
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...
|
|
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.
int EEPROM::Get |
( |
unsigned short |
address) | |
|
|
inline |
Get a single byte from the EEPROM.
- Parameters
-
address | the 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
-
address | the two byte address to read from. |
bytes | the memory location to store the data. |
length | the number of bytes to read. |
- Returns
- 0 on success, or -1 on timeout or other failure.
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
-
address | the two byte address to read from. |
length | the number of bytes to read. |
- Returns
- the number read from the EEPROM. If length is < 4, then the upper bytes are set to 0.
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
-
scl | The I2C SCL pin. Defaults to the Propeller default SCL pin. |
sda | The I2C SDA pin. Defaults to the Propeller default SDA pin. |
bool EEPROM::Put |
( |
const unsigned short |
address, |
|
|
const char |
byte |
|
) |
| |
|
inline |
Put a byte into the EEPROM.
- Parameters
-
address | the two byte address to write to. |
byte | the 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
-
address | the two byte address to write to. |
bytes[] | the array of bytes to write. |
size | the number of bytes to write. |
- Returns
- success or failure
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
-
address | the two byte address to write to. |
bytes | the set of bytes to store. If length is less than 4, Put stores the bytes beginning with the LSB. |
length | the number of bytes to store, up to 4. |
- Returns
- success or failure
The documentation for this class was generated from the following file: