static PROGMEM byte array - error in subroutine

Hi,

I faced a strange problem, and i cannot find a solution...

I using the variable with this form:
static const PROGMEM byte NFCkey[1024]= {0x30,0xb4,0xc6,0x0c,0xbe.....}

I read data from this array and display - and seems everything okay. But i want a sub, to read from this array a 16 byte block, and write to global array:

byte NFCdata[16]= {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
.....
pointer=0; pointer2=0;
NFCdata[pointer2]=NFCkey[pointer];pointer++;pointer2++;NFCdata[pointer2]=NFCkey[pointer];pointer++;pointer2++; .....

This is also work in main() - but this is never worked in subroutine, like this:

void NFCreadkey(int block){
pointer=block*16 ; pointer2=0;
NFCdata[pointer2]=NFCkey[pointer];pointer++;pointer2++;NFCdata[pointer2]=NFCkey[pointer];pointer++;pointer2++; ....
};

If this code called from sub, return with 0 array. If i replace the PROGMEM array with the counter, i get again get good numbers... Like this:
NFCdata[pointer2]=pointer;pointer++;pointer2++;NFCdata[pointer2]=pointer;pointer++;pointer2++; ....

it seems to be error in the PROGMEM calculation routine, in the compiler!!!
I try this with for() (same error). But, if i read from the PROGMEM array with a static index, the result is good again:
NFCdata[pointer2]=NFCkey[0];pointer2++;NFCdata[pointer2]=NFCkey[1];

Help!
This is really a compiler error, or i make mistakes?!?!?

Thank!

Ui: sorry for my english...

You have not understood that arrays in PROGMEM are not accessible like arrays in SDRAM. You need to read PROGMEM arrays byte-by-byte with "pgm_read_*_near()". Look at the docs.

  for (int i=0; i<sizeof NFCdata; i++)
  {
    NFCdata[i] = pgm_read_byte(&NFCkey[i]);

  }

Ahhhh, yess!!!!!

Thank you, you saved my life!!! Or - what is even better - my project! :slight_smile: :slight_smile: