This is eeprom write and read operation
and
shared setup function where the eeprom gets read the stored eeprom value
int saved_insrt_len,
int write_read_IntIntoEEPROM(int address, String cmd)
{
int data = cmd.substring(8).toInt();
int current_value = readIntFromEEPROM(address);
int verify_value;
if(current_value != data )
{
// Create a data structure with the integer number.
// Store the data structure into the EEPROM at the specified address.
EEPROM.put(address, data);
EEPROM.get(address, verify_value);
if (verify_value != data)
{
return EEPROM_CONFIG_ERROR;
}
}
EEPROM.write(EEPROM_MAGIC_ADDR, EEPROM_MAGIC_VAL);
// Return the integer value stored in the data structure.
return data;
}
int readIntFromEEPROM(int address)
{
// Create a data structure to store the retrieved data.
int data;
// Read the data structure from the EEPROM at the specified address.
EEPROM.get(address, data);
// Optional debug output
// Serial.print("EEPROM valid: ");
// Serial.println(is_eeprom_valid() ? "Yes" : "No");
// Serial.print("saved_insrt_len: ");
// Serial.println(saved_insrt_len);
// Return the integer value stored in the data structure.
return data;
}
void setup()
{
//delay for tmc26x setup/powerup
delay(100);
Serial.begin(SERIAL_BAUD_RATE);
/initiliaze the GPIO pins/
GPIO_init();
/initiliaze the tmc26x driver ic/
tmc26x_init();
delay(2000);
/Run homing sequence according the configured homing sequence/
homing();
motor_pos = 0;
delay(2000);
saved_insrt_len = readIntFromEEPROM(MEM_ADDR_INSRT_LEN);
// Serial.print("saved_insrt_len : ");
// Serial.println(saved_insrt_len);
}