Retrieving table data from flash

Hello there,

I have come up with a tester using the Atmega328p, it tests up to 7 different products, these may have up to 60 points of contacts that are conveyed to the Atmega’s analog inputs using 4 multiplexers. The range for the value of each of these up to 60 points are stored in a 16x4 array, one for each of the seven products.

As you may imagine, the Atmega ran out of memory, so, with the use of the updated Flash library from Arduinana.org (found here), I moved all the 16x4 tables to flash.

Knowing that the flash has an expected life of around 10,000 cycles, I would like to avoid sending the tables to flash every time the testers are turned on. To do this, I would like to write the table once, when the Atmega has been first programmed with the tester’s code, and then just read the data every time the tester is powered up.

I made an attempt to this, but I cannot access the tables later on as they don’t get declared (obviously) after a power cycle, a trimmed copy of my code is below, I left only two tables as an example, my attempt at doing this is commented out at the begining of the runOnce() function.

My question is, is there a way to retrieve the whole table information in flash after it has been sent? How?

/*
 *  Product tester program
 * 	Several products tested using tester ID 
 *  to select appropriate min/max values
 */

#include <EEPROM.h>
#include <Flash.h>

// Variables declaration
*
*
*

// *******************   Generic MIN/MAX arrays
int minimum[16][4]={
  //Product Min
  {0, 0, 0, 0},//0
  {0, 0, 0, 0},//1
  {0, 0, 0, 0},//2
  {0, 0, 0, 0},//3
  {0, 0, 0, 0},//4
  {0, 0, 0, 0},//5
  {0, 0, 0, 0},//6
  {0, 0, 0, 0},//7
  {0, 0, 0, 0},//8
  {0, 0, 0, 0},//9
  {0, 0, 0, 0},//10
  {0, 0, 0, 0},//11
  {0, 0, 0, 0},//12
  {0, 0, 0, 0},//13
  {0, 0, 0, 0},//14
  {0, 0, 0, 0},//15
};

//MaxSpec values
int maximum[16][4]={
  //Product Max
  {1024, 1024, 1024, 1024},//0
  {1024, 1024, 1024, 1024},//1
  {1024, 1024, 1024, 1024},//2
  {1024, 1024, 1024, 1024},//3
  {1024, 1024, 1024, 1024},//4
  {1024, 1024, 1024, 1024},//5
  {1024, 1024, 1024, 1024},//6
  {1024, 1024, 1024, 1024},//7
  {1024, 1024, 1024, 1024},//8
  {1024, 1024, 1024, 1024},//9
  {1024, 1024, 1024, 1024},//10
  {1024, 1024, 1024, 1024},//11
  {1024, 1024, 1024, 1024},//12
  {1024, 1024, 1024, 1024},//13
  {1024, 1024, 1024, 1024},//14
  {1024, 1024, 1024, 1024},//15
  };



void setup(){
// I/O and general Setup
 
}

// ********************************* Program starts here ******
void loop() {

	runOnce();
	
// Program body goes here

}



void runOnce() {
  
  if (!started) {
//    int toolID = EEPROM.read(toolIDaddr);
//    Serial.println(toolID);
//    if (arduinoID != thisToolID) {
//        EEPROM.write(toolIDaddr, thisToolID);
      
		  //****************************** MIN/MAX values - product1
		  FLASH_TABLE(int, product1min, 4,
			// Product1 minimum values
			{944,   0, 944, 944},//0
			{944,   0, 944, 944},//1
			{944,   0, 944, 944},//2
			{944,   0, 0, 0},//3
			{944,   0, 944, 944},//4
			{944,   0, 944, 944},//5
			{400,   0, 944, 944},//6
			{944,   0, 944, 944},//7
			{  0, 944,   0,   0},//8
			{  0, 944,   0,   0},//9
			{400, 944, 944,   0},//10
			{944, 944,   0,   0},//11
			{400, 944, 944,   0},//12
			{  0, 944, 944, 944},//13
			{400,   0, 944,   0},//14
			{400, 944, 944,   0},//15
		  );
		  
		  //MaxSpec values
		  FLASH_TABLE(int, product1max, 4,
			// Product1 maximum values
			{1024,   80, 1024, 1024},//0
			{1024,   80, 1024, 1024},//1
			{1024,   80, 1024, 1024},//2
			{1024,   80, 1024, 1024},//3
			{1024,   80, 1024, 1024},//4
			{1024,   80, 1024, 1024},//5
			{600,   80, 1024, 1024},//6
			{1024,   80, 1024, 1024},//7
			{  80, 1024,   80,   80},//8
			{  80, 1024,   80,   80},//9
			{600, 1024, 1024,   80},//10
			{1023, 1024,   80,   80},//11
			{600, 1024, 1024,   80},//12
			{  80, 1024, 1024, 1024},//13
			{600,   80, 1024,   80},//14
			{600, 1024, 1024,   80},//15
			);
		  
		  //****************************** MIN/MAX values - product2
		  FLASH_TABLE(int, product2min, 4,
			// Product2 minimum values
			{944,   0, 944, 944},//0
			{944,   0, 944, 944},//1
			{944,   0, 944, 944},//2
			{944,   0, 0, 0},//3
			{944,   0, 944, 944},//4
			{944,   0, 944, 944},//5
			{400,   0, 944, 944},//6
			{944,   0, 944, 944},//7
			{  0, 944,   0,   0},//8
			{  0, 944,   0,   0},//9
			{400, 944, 944,   0},//10
			{944, 944,   0,   0},//11
			{400, 944, 944,   0},//12
			{  0, 944, 944, 944},//13
			{400,   0, 944,   0},//14
			{400, 944, 944,   0},//15
		  );
		  
		  //MaxSpec values
		  FLASH_TABLE(int, product2max, 4,
			//Product2 maximum values
			{1024,   80, 1024, 1024},//0
			{1024,   80, 1024, 1024},//1
			{1024,   80, 1024, 1024},//2
			{1024,   80, 1024, 1024},//3
			{1024,   80, 1024, 1024},//4
			{1024,   80, 1024, 1024},//5
			{600,   80, 1024, 1024},//6
			{1024,   80, 1024, 1024},//7
			{  80, 1024,   80,   80},//8
			{  80, 1024,   80,   80},//9
			{600, 1024, 1024,   80},//10
			{1023, 1024,   80,   80},//11
			{600, 1024, 1024,   80},//12
			{  80, 1024, 1024, 1024},//13
			{600,   80, 1024,   80},//14
			{600, 1024, 1024,   80},//15
			);
      
//      }
        // *********************************** Identify which product has been plugged
      int model = 0;
      int boardID = analogRead(ID);
      Serial.print("BoardID = ");Serial.println(boardID);
      if (boardID >= 100 && boardID <= 190) {
			model = 1;  // Product1 detected
			Serial.println("Product1 detected");
        } else {
			if (boardID >= 195 && boardID <= 290) {
				model = 2;  // Product2 detected
				Serial.println("Product2 detected");
			}
        }
  
		// **************************** Load the appropriate table to the generic min/max arrays
      switch (model) {
			//************** Product1 detected
			case 1:
			  for(int i = 0; i < pinQty; i++){
					for(int k = 0; k < 4; k++){
					  minimum[i][k] = product1min[i][k];
					  maximum[i][k] = product1max[i][k];
					}
			    }
			break;
			//************** Product2 detected
			case 2:
				for(int i = 0; i < pinQty; i++){
					for(int k = 0; k < 4; k++){
					  minimum[i][k] = product2min[i][k];
					  maximum[i][k] = product2max[i][k];
				    }
			    }
			break;

			default:
			  Serial.print("Model = ");Serial.println(model);
			break;
        }
    }
  started = true;
}