First off I'm relatively new to coding so please bare with me.
I cobbled together some code to read the internal AVR EEPROM to Serial. Nothing fancy. It can read the value at an address, write a value to an address, or list the address/values.
/* Program based off work from the below source
Arduino EEPROM Read/Write using Serial Monitor
https://circuits.io/circuits/1366613-arduino-eeprom-read-write-using-serial-monitor
Author: Eric W. Johnson
Date 13th December 2015
*/
#include <EEPROM.h>
// ********************************
// Declare and initialize variables
String strCommand = ""; // string variable to hold the command
char chrInput[128]; // character variable for reading bytes
boolean bDisplayMessage = true; // boolean variable to determine whether or not to display message.
int iLocRead = 0; // integer variable for location of 'read'
int iLocWrite = 0; // integer variable for location of 'write'
int iLocList = 0; // integer variable for location of 'list'
int iLocSpace = 0; // integer variable for location of space
int iAddress = 0; // integer variable for EEPROM address
byte bytValue = 0; // byte variable for value stored at EEPROM address
String strTmp = ""; // temporary string variable
// ********************************
// SETUP serial monitor
void setup() {
Serial.begin(9600); // Set baud rate for serial monitor
}
// ********************************
void loop() {
// Display informational message if it's not already displayed
if (bDisplayMessage) {
Serial.println("\nPlease enter a command. Read <address>, Write <address> <value> Or List");
bDisplayMessage = false; // suppress message, for now.
}
// Get command and store in a string
if (Serial.available()) {
//Wait a bit, then read the serial buffer
delay(100);
if (false) {
Serial.readBytes(chrInput, 128);
strCommand = String(chrInput);
}
else {
strCommand = Serial.readString();
strCommand.toUpperCase(); // change to upper case to allow mixed case commands
}
// Determine if it's a read or a write command
iLocRead = strCommand.indexOf("READ"); // location of 'read'
iLocWrite = strCommand.indexOf("WRITE"); // location of 'write'
iLocList = strCommand.indexOf("LIST"); // location of 'list'
// Display error message if command not found.
if (iLocRead < 0 && iLocWrite < 0 && iLocList < 0) {
Serial.println("\nNo read or write command found, please try again.");
}
else {
if (iLocRead >= 0) { // Process read command
strTmp = strCommand.substring(iLocRead + 5);
iAddress = strTmp.toInt();
bytValue = EEPROM.read(iAddress);
Serial.println("The contents of EEPROM address " + String(iAddress) + " is " + String(bytValue));
}
else if (iLocList >= 0) { // List locations and values for a set number
Serial.println("List EEPROM");
Serial.println();
Serial.print("Loc");
Serial.print("\t");
Serial.print("Value");
Serial.println();
iAddress = 0;
while (iAddress < 45) {
bytValue = EEPROM.read(iAddress);
Serial.print(iAddress);
Serial.print("\t");
Serial.print(bytValue, DEC);
Serial.println();
iAddress++;
}
}
else { // Process write command
strTmp = strCommand.substring(iLocWrite + 6);
iAddress = strTmp.toInt();
iLocSpace = strTmp.indexOf(" "); // location of space
strTmp = strTmp.substring(iLocSpace + 1);
bytValue = strTmp.toInt();
EEPROM.write(iAddress, bytValue);
Serial.println("The value of " + String(bytValue) + " has been saved to EEPROM address " + String(iAddress));
}
} // END else{ Process Command
bDisplayMessage = true; // Get next command
} // END if (Serial.available())
} // END void loop()
This works well but it can only access the internal EEPROM. I'd like to have a version that can read/write from the "Master" AVR to the "Target" AVR's EEPROM via ISP. Very similar to Nick Gammon's excellent Atmega_Board_Programmer. I had hoped to simply add the ability to this Programmer sketch but so far have been unsuccessful. There is a lot going on in his program and my skills just are lacking.