Go Down

Topic: Function fails with passed in variable, but works if set manually. (Read 2500 times) previous topic - next topic

westfw

Yep.  I came up with the same fix as Pyro65, once I looked at it more carefully.
You didn't have ANY special code to read the pointers from flash...

Beats me why it worked with constants, though.  I guess the compiler did most of the pointer arithmetic at compile time, so the step where it fetched inappropriate pointers from RAM was skipped.

allenhuffman



I really believe it's a compiler issue.

Nope,

Because your flasharray is an array of progmem pointers, not data. You must use pgm_read_word to retrieve the pointer.

Code: [Select]
Serial.println((__FlashStringHelper*)flashArray[i]);

This is reading the i'th value in sram, you placed the data in PROGMEM. I can see that it works on occasion for you ( and my test ), but it is still wrong.


Yes, agreed, and understood. That's what I pointed out I do in my production code (see my post from April 10, 2013).

My issue was not with that, at all,, but with the inconsistency I see with things being done behind the scenes with the compiler and preprocessor and such. I really expect I am doing more intense stuff than probably 99% of most Ardunio uses ever deal with :)  It's fun.

The challenge I faced was making code that could generate to use RAM or FLASH by altering a #define, to make it easy for end-users that do not get involved with how the tools work.
Embedded Software Engineer
UNO | Leonardo | Due | Teensy | BASIC Stamp | OS-9 RTOS
http://www.subethasoftware.com - Established in 1990.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy