PROGMEM and struct/class members
i put class in program space , able access members having difficulty doing in simplest of examples. here code:
and produces following output:
line 3 looks unusual, i'm supposing small enough programs, flash locations accessible using instructions read ram. (i see similar result in line 6 of eliminate print() statements.)
lines 9 , 10 ones trouble me. cannot seem retrieve value of member of flash. searched forum discussions on , there several showed how put objects flash found none demonstrated how retrieve them.
this built using 1.5.8 ide 1.0.6 ide produces following error (after clean complaints relating typedef):
any on retrieving member variables flash appreciated! first real project , i've exceeded ram capacity!
code: [select]
// fun with progmem
#include <avr/pgmspace.h>
#define line {serial.print(l++);serial.print(" ");}
typedef unsigned const int prog_uint16_t;
int iram=11;
struct a {
public:
prog_uint16_t a;
a():a(33){};
prog_uint16_t * getaaddr() const { return &a; }
};
progmem prog_uint16_t iflash=22;
a const progmem a;
void setup() {
int l=1;
serial.begin(115200);
delay(2000); //alow time open serial console
line; serial.print(f("single int/ram value ")); serial.println(iram);
line; serial.print(f("single int/ram address ")); serial.println((int)&iram);
serial.println("");
line; serial.print(f("single int/progmem value/ram ")); serial.println(iflash);
line; serial.print(f("single int/progmem address ")); serial.println((int)&iflash);
line; serial.print(f("single int/progmem value/flash ")); serial.println(pgm_read_word(&iflash));
serial.println("");
line; serial.print(f("class int/progmem value/ram ")); serial.println(a.a);
line; serial.print(f("class int/progmem address ")); serial.println((int)&a.a);
line; serial.print(f("class int/progmem address ")); serial.println((int)a.getaaddr());
line; serial.print(f("class int/progmem value/flash ")); serial.println(pgm_read_word(&a.a));
line; serial.print(f("class int/progmem value/flash ")); serial.println(pgm_read_word(a.getaaddr()));
}
void loop() {
}
and produces following output:
code: [select]
1 single int/ram value 11
2 single int/ram address 256
3 single int/progmem value/ram 22
4 single int/progmem address 415
5 single int/progmem value/flash 22
6 class int/progmem value/ram 17967
7 class int/progmem address 417
8 class int/progmem address 417
9 class int/progmem value/flash 0
10 class int/progmem value/flash 0
line 3 looks unusual, i'm supposing small enough programs, flash locations accessible using instructions read ram. (i see similar result in line 6 of eliminate print() statements.)
lines 9 , 10 ones trouble me. cannot seem retrieve value of member of flash. searched forum discussions on , there several showed how put objects flash found none demonstrated how retrieve them.
this built using 1.5.8 ide 1.0.6 ide produces following error (after clean complaints relating typedef):
code: [select]
progmem:18: error: causes section type conflict
any on retrieving member variables flash appreciated! first real project , i've exceeded ram capacity!
i don't understand why want this.
text or tables data can created in progmem. big in class want in progmem ?
what else have in ram ?
if need many buffers ethernet , sd card , pixel display , many more, going need arduino mega 2560 someday anyway.
text or tables data can created in progmem. big in class want in progmem ?
what else have in ram ?
if need many buffers ethernet , sd card , pixel display , many more, going need arduino mega 2560 someday anyway.
Arduino Forum > Using Arduino > Programming Questions > PROGMEM and struct/class members
arduino
Comments
Post a Comment