I have external ADC which i use through SPI. In my sketch i initialize RAM array, for example short int data[100], and use it for storing ADC values ( 1 value - 2Bytes). When data[100] array is fully filled with values, i want to copy this array from RAM to Flash. Why i want to do this? Because i need to store signal at sampling rate ~fs=100Hz, for 40sec, and RAM memory isn't enough.
Code something like that:
void loop(){
//when data[100] is fully filled
for(int i = 0; i<100; i++){
flashdata [ i ] PROGMEM = data [ i ] ; //this line doesn't work, it's just example how it might work
};
}
You can't. The flash ram is written once when the chip is booted and it is read-only after that.
You would have to write the samples to, for example, an external EEPROM.
Can't be done. As PaulS mentioned, Flash is read-only at run-time.
Some of the alternatives to what you want to do will likely be too slow, or will not have sufficient storage (EEPROM, SD card).
You haven't mentioned what size your 40 seconds of samples will be, or how much time you have between samples, but I think the only real answer will be to use an external memory. Preferably a fairly fast one, like SRAM or FRAM (SRAM is volatile, FRAM is non-volatile).
If you find that SRAM or FRAM isn't quite fast enough to keep up, another alternative it to use a second microprocessor (perhaps another Arduino, to do the actual storage, dividing the workload.
Of course, there's always a larger arduino at a higher frequency, like the Due. It might help if you tell us the size of the sample storage you need, the time between samples. You could also post your entire code. It might help us to come up with some ides for reducing the storage needed.