PropWare  3.0.0.229
C++ objects and CMake build system for Parallax Propeller
Eeprom_Demo.cpp

Read from and write to the EEPROM that comes with your Propeller

cmake_minimum_required(VERSION 3.12)
find_package(PropWare REQUIRED)
project(Eeprom_Demo)
create_simple_executable(${PROJECT_NAME} Eeprom_Demo.cpp)
static const uint8_t MAGIC_ARRAY_1[] = "DCBA0";
static const size_t ARRAY_SIZE_1 = sizeof(MAGIC_ARRAY_1);
static const char MAGIC_ARRAY_2[] = "Hello, world!";
static const size_t ARRAY_SIZE_2 = sizeof(MAGIC_ARRAY_2);
static const uint16_t TEST_ADDRESS = 32 * 1024; // Place the data immediately above the first 32k of data
int main() {
Eeprom eeprom;
// Here we have some core access of the EEPROM, passing it the address with every call. This is great for non-ASCII
// data, but it gets tedious.
pwOut << "EEPROM ack = " << eeprom.ping() << '\n';
bool success = eeprom.put(TEST_ADDRESS, MAGIC_ARRAY_1, ARRAY_SIZE_1);
pwOut << "Put status: " << success << '\n';
pwOut << "Received character: " << (char) eeprom.get(TEST_ADDRESS) << '\n';
pwOut << "Received character: " << (char) eeprom.get(TEST_ADDRESS + 1) << '\n';
pwOut << "Received character: " << (char) eeprom.get(TEST_ADDRESS + 2) << '\n';
pwOut << "Received character: " << (char) eeprom.get(TEST_ADDRESS + 3) << '\n';
pwOut << "Received character: " << (char) eeprom.get(TEST_ADDRESS + 4) << '\n';
// This is great for ASCII data, because we have access to the Printer and Scanner classes.
pwOut << "Notice that PropWare::Eeprom also implements the PropWare::PrintCapable \n"
"and PropWare::ScanCapable interfaces. So we could also use the Propware::Printer \n"
"and PropWare::Scanner objects for reading and writing.\n";
Printer eepromPrinter(eeprom);
Scanner eepromScanner(eeprom);
// Reset the EEPROM address
eeprom.set_memory_address(TEST_ADDRESS);
// Note that the newline is required, or else the scanner won't know when to stop reading
eepromPrinter << MAGIC_ARRAY_2 << '\n';
char buffer[ARRAY_SIZE_2];
// Reset the EEPROM address so that we can read what we just wrote
eeprom.set_memory_address(TEST_ADDRESS);
// Read from the EEPROM
eepromScanner.gets(buffer, ARRAY_SIZE_2);
pwOut << "Received \"" << buffer << "\" from the EEPROM!\n";
return 0;
}
printer.h
PropWare::Scanner
Interface for all classes capable of scanning.
Definition: scanner.h:43
eeprom.h
main
int main(void)
Definition: GraphicsTest.c:20
PropWare::Eeprom
EEPROM reader/writer.
Definition: eeprom.h:33
scanner.h
pwOut
PropWare::Printer pwOut
Most common use of printing in PropWare applications (not thread safe; see PropWare::pwSyncOut for mu...
char
PropWare::Printer
Container class that has formatting methods for human-readable output. This class can be constructed ...
Definition: printer.h:76
PropWare
Generic definitions and functions for the Parallax Propeller.
Definition: runnable.h:33