This is my first post, forgive me if my format is strange or incorrect.
I've spent hours on this so far and I'm hoping someone else can see a simple mistake I'm making.
Regarding my (attached) sketch, I am simply storing some 32-bit (unsigned long) numbers in the PROGMEM area.
But when I retrieve them and Serial.print them, they're incorrect.
I expect to see this output:
But I see this:
It appears that for some reason, Bit31 is acting as a sign and only the lower 16-bits are correctly reported. But these are supposed to be unsigned longs.
Can anyone see a problem with what I'm doing or have a solution?
Thank you so much!!!
sketch_jan06a.ino (610 Bytes)
Sorry, I am also pasting the code here for easier reference:
#define ARRAY_SIZE (4)
const unsigned long u4_LOOKUP_TABLE[ARRAY_SIZE] PROGMEM =
unsigned char u1_s_idx;
unsigned long u4_s_lookupValue;
for(u1_s_idx = 0; u1_s_idx < ARRAY_SIZE; u1_s_idx ++)
u4_s_lookupValue = (unsigned long*)pgm_read_dword(&(u4_LOOKUP_TABLE[u1_s_idx]));
Serial.print(u1_s_idx ); Serial.print(' ');
Serial.print(u4_s_lookupValue, HEX); Serial.print('\n');
u4_s_lookupValue = [color=red](unsigned long*)[/color]pgm_read_dword(&(u4_LOOKUP_TABLE[u1_s_idx]));
You need to get rid of the cast to pointer. It's NOT a pointer, and pointers on AVR are only 16bits, so you're throwing away the high bytes (and then sign-extending, apparently.)
u4_s_lookupValue = pgm_read_dword(&(u4_LOOKUP_TABLE[u1_s_idx]));
Wow. Excellent. Thank you so much for your help, I very much appreciate it!!