PropWare
2.1.2
C++ objects and CMake build system for Parallax Propeller
|
Click here for docs on the
develop
branch.
#include <eeprom.h>
Public Member Functions | |
void | Init (const int scl=28, const int sda=29) |
bool | Put (const unsigned short address, const char byte) |
bool | Put (unsigned short address, char bytes[], int size) |
bool | PutNumber (const unsigned short address, const int bytes, const int length) |
int | Get (unsigned short address) |
int | Get (unsigned short address, char bytes[], const int length) |
int | GetNumber (unsigned short address, int length) |
Access I2C EEPROMs.
Valid EEPROM data addresses are in the range 0 to 0xFFFF for 64KB EEPROMS, and 0 to 0x7FFF for 32KB EEPROMs.
This driver was written to work with the AT24C512C EEPROM from Atmel, but it may work with other I2C EEPROMs.
int libpropeller::EEPROM::Get | ( | unsigned short | address | ) |
int libpropeller::EEPROM::Get | ( | unsigned short | address, |
char | bytes[], | ||
const int | length | ||
) |
Get a block of bytes from the EEPROM.
Note: This function takes care of the page reads from the EEPROM.
address | the two byte address to read from. |
bytes | the memory location to store the data. |
length | the number of bytes to read. |
Definition at line 120 of file eeprom.h.
int libpropeller::EEPROM::GetNumber | ( | unsigned short | address, |
int | length | ||
) |
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.
address | the two byte address to read from. |
length | the number of bytes to read. |
Definition at line 158 of file eeprom.h.
void libpropeller::EEPROM::Init | ( | const int | scl = 28 , |
const int | sda = 29 |
||
) |
bool libpropeller::EEPROM::Put | ( | const unsigned short | address, |
const char | byte | ||
) |
bool libpropeller::EEPROM::Put | ( | unsigned short | address, |
char | bytes[], | ||
int | size | ||
) |
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.
address | the two byte address to write to. |
bytes[] | the array of bytes to write. |
size | the number of bytes to write. |
Definition at line 53 of file eeprom.h.
bool libpropeller::EEPROM::PutNumber | ( | const unsigned short | address, |
const int | bytes, | ||
const int | length | ||
) |
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).
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. |
Definition at line 85 of file eeprom.h.