[SOLVED] How do I store and retrieve 24 bit unsigned long?

When I store a bunch of 24 bit unsigned long numbers into PROGMEM, then try and retrieve them, I only get back 16bits. For example:

const unsigned long codes[] PROGMEM = {0xFF34AC,0xFF32AD,0xFF629D};

void check() {
  unsigned long a = pgm_read_word(&codes[0]);
  unsigned long b = pgm_read_word(&codes[1]);
  unsigned long c = pgm_read_word(&codes[2]);
  Serial.println(a,HEX);
  Serial.println(b,HEX);
  Serial.println(c,HEX);
}

Produces this:

34AC
32AD
629D

And apparently there is no pgm_read_word_far in the Arduino libraries as there is in the standard pgmspace.h c++ library because when I try to use the far macro, I get a compile error:

exit status 1
'pgm_read_word_far' was not declared in this scope

So how do I store and retrieve 24 bit unsigned longs?

Thank you,

Mike

No, you're getting back 16 bits.

You want pgm_read_dword_near(), as you want to read a double-word (word is 16-bits on avr) from the near progmem. The _far() variants are used on boards with >64k of flash to read from locations after the first 64k (there are other complications to their use as well); that's not what you're trying to do.

0xFF34AC,0xFF32AD,0xFF629D

Those are 24 bits.

34AC
32AD
629D

Those are 16 bit ints.

According to this Sparkfun page the word data type is 16 bits (int).

groundFungus:

0xFF34AC,0xFF32AD,0xFF629D

Those are 24 bits.Those are 16 bit ints.

According to this Sparkfun page the word data type is 16 bits (int).

Yes, my mistake ... still can't read them back in their entirety though.

groundFungus:

0xFF34AC,0xFF32AD,0xFF629D

Those are 24 bits.Those are 16 bit ints.

According to this Sparkfun page the word data type is 16 bits (int).

DrAzzy:
No, you're getting back 16 bits.

You want pgm_read_dword_near(), as you want to read a double-word (word is 16-bits on avr) from the near progmem. The _far() variants are used on boards with >64k of flash to read from locations after the first 64k (there are other complications to their use as well); that's not what you're trying to do.

Thank you, I thought I had tried that, but maybe it was pgm_read_word_near that I tried... but I tried your suggestion and it worked perfectly. Thank you!

Glad to hear it - btw the reference for the pgmspace library is - avr-libc: <avr/pgmspace.h>: Program Space Utilities (this site also has the docs for the other libraries that are part of avr-libc, too).

pgm_read_dword() would work too - it's a synonym for pgm_read_dword_near().