i used data flash memory to store my code big size of array in arduino pro trinket board i succesfully store using PROGMEM but i want to access one by one location..i use pgm_read_byte_far for access flash memory my problem is i pass array value constant so its give perfect value but i use increment operator and pass to array value access its give garbage or wrong reading..why?? suppose i write array
guValue = pgm_read_byte_far(array[guData][0]);
{
guData++;
}
its give garbage or wrong value but
guValue = pgm_read_byte_far(array[5][0]);
here instead of 5 any constant digit from array write its give perfect array access...
what is problem i also dump guData variable on terminal its increment one by one....at the start its guData=0;...
mangukia:
how to access array without pgm_read_dword...
i just want to access array
const uint32_t array[7][2] PROGMEM = {
{0,0x610000},
{1000,0x640000},
{1000,0x660000},
{1000,0x680000},
{1000,0x6A0000},
{1000,0x6D0000},
{1000,0x6F0000},
};
The compiler does not know about PROGMEM, its a linker thing.
uint32_t guValue=array[5][1];
What is happening is the array indices are constants so the optimizing compiler will not keep the array, but put the value of array[5][1] inline. So reading from PROGMEM is not necessary.
It effectively optimizes to:
uint32_t guValue=0x6D0000;
In the loop the indices are deduced at runtime and will give garbage as the storage is in PROGMEM, not RAM. The pgm functions are required to access the different storage space.
If you turned of all optimizations, the constant version should fail too. So basically, if you mark something as PROGMEM, use the correct functions, one day after an update or change to your code, you could end up wasting a lot of time trying to work out what is happening.