Read from and write to the EEPROM that comes with your Propeller
cmake_minimum_required(VERSION 3.12)
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;
Eeprom eeprom;
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';
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);
eeprom.set_memory_address(TEST_ADDRESS);
eepromPrinter << MAGIC_ARRAY_2 << '\n';
char buffer[ARRAY_SIZE_2];
eeprom.set_memory_address(TEST_ADDRESS);
eepromScanner.gets(buffer, ARRAY_SIZE_2);
pwOut <<
"Received \"" << buffer <<
"\" from the EEPROM!\n";
return 0;
}