Problems with Flash.h library

Hello,

I have a problem with the Flash.h library created by Mikal Hart: If I want to use a constant array witch contains more than 327 Bytes, I get wrong content. The code I use, is below:

#include <avr/Flash.h>

FLASH_ARRAY(char, test, 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A',  'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A',  
                        'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 
                        'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 
                        'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 
                        'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 
                        'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 
                        'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 
                        'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 
                        'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A',
                        'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A');

int i = 0;
    
void setup() 
{
  Serial.begin(9600); // initialize serial communication
}

void loop()
{
  while(i != 1599)
  {
    Serial.write(test[i]);
    i++;
  }
}

The output I get is: “AAAAAAAAAAAAAAAAAAAAA” (327 times)
But if I put only one A more into the array, the output is:
" AAAAAAAAAAAAAAAAAAAAA"

Has anyone an idea, how I can fix this?

Thanks a lot,
Greetz Louis

Which board are you using?

I'm using the Arduino Duemilanove board...

It looks to me like you are declaring an array of 327 characters, and then printing all 1,599 of them.

That's right and in this case, the output is right. It shows 327 times the A and then other symbols because the bytes after the 327th byte are not defined.

The problem is the outut is not longer right if I declare an array eveb bigger then 327 bytes. Then I get:

"different symbols..." "327+x times the A" "another different symbols"

That means I cannot get exactly the content of the declared array.

Have you checked out how much free memory you have when the sketch is compiled?

There are a number of threads in the forum where people are experiencing issues because they have run out of available program memory, even though the sketch size is still well within the limits of the chip they are using.

I think there should be enough free memory space, the flash ROM is 32KB and the program only uses 2KB.

I suppose the management in the library has faults, I contaced Mikal Hart but he does not answer, yet…

Greetz

#include <avr/Flash.h>

Is the Flash library installed in the correct location?

Are you using the latest version? From Mikal’s web site…

You can retrieve the version of the Flash library by inspecting FLASH_LIBRARY_VERSION.

Finally, are you certain the “” aren’t left-over from the previous run? I ask because your code with the latest library works fine for me. I suggest changing setup to this so you can clearly spot the start of a run…

void setup()
{
  Serial.begin(9600); // initialize serial communication
  delay( 3000 );
  Serial.println( "----------------------------------------------------------------------" );
}

The location of library is right. The other aspects, I will check tomorrw, thanks a lot for the ideas and the program code :)

Greetz

Thanks a lot, the problem is solved!

It was not a problem of the library, the serial communication was unclear. Therefore I received symbols that did not belong to the array. The content of the array is right until the overflow of the flash memory space.

Topic can be closed, thanks.

Greetz Louis