Go Down

Topic: prog_char and pgm_read_byte won't work (Read 4937 times) previous topic - next topic

fcrembis



Running the following program results with "10B 91" on the Serial Monitor indicating 0x91 is stored at or read from address 0x010B rather than 0x00. Please advise. Any and all help is appreciated.

Code: [Select]




#include<avr/pgmspace.h>

byte flag=0;
prog_char jazz0=0x00;

void setup() {
 Serial.begin(9600);
};

void loop() {
 if (flag == 0) {
   flag=1;
   Serial.print  ((int)&jazz0, HEX);
   Serial.print  (' ');
   Serial.println(pgm_read_byte(&jazz0), HEX);
 };
};



Coding Badly

#1
Dec 17, 2009, 06:59 am Last Edit: Dec 17, 2009, 06:59 am by bcook Reason: 1

I have no idea why your code does not work but this does work...

Code: [Select]
prog_char jazz0 PROGMEM =0x00;

Groove

#2
Dec 17, 2009, 10:10 am Last Edit: Dec 17, 2009, 10:11 am by GrooveFlotilla Reason: 1
Can someone explain the syntax of this one please?
If
Code: [Select]
typedef char PROGMEM prog_char; (from "pgmspace.h").

isn't
Code: [Select]
prog_char jazz0 PROGMEM =0x00;
somewhat tautological?

Would a simple "const" suffice?
Per Arduino ad Astra

fcrembis

Your help is appreciated. "prog_char jazz0 PROGMEM =0x00;" works. All is now well.

Coding Badly

Quote
isn't somewhat tautological?

My suspicion is there is a bug or deficiency in the compiler.

Quote
Would a simple "const" suffice?

No.  The difference is where the data is stored.  PROGMEM places the data in Flash.  const places the data in SRAM.

westfw

Looks like the same bug described here:
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1228107706/0#0

There hasn't been any word on this since I submitted the bug to the gcc group back in august.

Go Up