Pages: [1]   Go Down
Author Topic: prog_char and pgm_read_byte won't work  (Read 2673 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 2
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset



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:



#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);
  };
};


Logged

Global Moderator
Dallas
Online Online
Shannon Member
*****
Karma: 208
Posts: 12936
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


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

Code:
prog_char jazz0 PROGMEM =0x00;
« Last Edit: December 17, 2009, 12:59:52 am by bcook » Logged

UK
Offline Offline
Faraday Member
**
Karma: 17
Posts: 2884
Gorm deficient
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Can someone explain the syntax of this one please?
If
Code:
typedef char PROGMEM prog_char;
(from "pgmspace.h").

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

Would a simple "const" suffice?
« Last Edit: December 17, 2009, 04:11:09 am by GrooveFlotilla » Logged

Per Arduino ad Astra

0
Offline Offline
Newbie
*
Karma: 0
Posts: 2
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Global Moderator
Dallas
Online Online
Shannon Member
*****
Karma: 208
Posts: 12936
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 135
Posts: 6763
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: [1]   Go Up
Jump to: