3

Consider this snippet, compiled with Arduino IDE:

PROGMEM  char charSet[]  = { 0x0, 0x8, 0x4, 0xc, 0x2, 0xA , 0x6, 0xE, 0x1, 0x9,0x5, 0xD, 0x3,0xB,0x7,0xF };
char reversed[]          = { 0x0, 0x8, 0x4, 0xc, 0x2, 0xA , 0x6, 0xE, 0x1, 0x9,0x5, 0xD, 0x3,0xB,0x7,0xF };
char ff;

for (int i=0; i < 16; i++) {
    Serial.print(" ");
    Serial.print(reversed[i], HEX);
}

Serial.println(" ");
for (int i=0; i < 16; i++) {
    Serial.print(" ");
    ff = pgm_read_byte(&charSet[i]);
    Serial.print(ff);
}

I would expect the two for loops to produce same output. But the output is:

  0 8 4 C 2 A 6 E 1 9 5 D 3 B 7 F
  FFFFFF94 FFFFFFB0 6 FFFFFF80 FFFFFF91 FFFFFFC7 3 62 FFFFFFE3 E FFFFFF94 5E 29 FFFFFF99 23 39

What am I missing?

4 Answers 4

4

Yes, the const keyword is missing.

Probably it is not a good idea to use prog_char, as it is marked as deprecated in gcc-avr, see avr/pgmspace.h

1

Well the answer was the PROGMEM declaration. I had to move it out from function, adding const keyword. Other changes as datatypes were not working.

The full answer is on Arduino forum.

0

You have the wrong datatype. From http://arduino.cc/en/Reference/PROGMEM:

Some cryptic bugs are generated by using ordinary datatypes for program memory calls.

You can't use char — you have to use prog_char

So:

PROGMEM prog_char charSet[] = {0x0, 0xB}

That should work.

by the way: You don't have to do Serial.println(" "); You can just do Serial.println();

0
PROGMEM  char charSet[] = ...

This is not good - for PROGMEM data, you can't use ordinary in-memory types. What you should do is

PROGMEM  prog_char charSet[] = ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.