Pages: [1]   Go Down
Author Topic: PROGMEM no longer working with 0013?  (Read 977 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 22
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The code below was working for me in 0012 0011 (see update below), but it seems to crash the AVR / return to the bootloader on the strcpy_P() line when uploaded to a stock diecimila.

Code:
/*
*PROGMEM test
*/
#include <avr/pgmspace.h>

char string_1[] PROGMEM = "String 1";
char string_2[] PROGMEM = "String 2";
char string_3[] PROGMEM = "String 3";
char string_4[] PROGMEM = "String 4";
char string_5[] PROGMEM = "String 5";

PGM_P PROGMEM string_table[] =
{
   string_1,
   string_2,
   string_3,
   string_4,
   string_5
};

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

char buffer[10];
void loop()                     // run over and over again
{
    for (unsigned char i = 0; i < 5; i++)
   {
       strcpy_P(buffer, (char * )pgm_read_word(&(string_table[i])));
       Serial.println( buffer );
       delay( 500 );
    }
}

update: code worked in 0011, not 0012
« Last Edit: February 25, 2009, 04:23:21 am by ahoeben » Logged

Austin, TX USA
Offline Offline
God Member
*****
Karma: 4
Posts: 997
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That PROGMEM stuff is awfully subtle.  If you change the string_table to

Code:
PROGMEM const char *string_table[] =

it will work under 0013.  (At least it does for me.)

Mikal
« Last Edit: February 24, 2009, 09:06:11 am by mikalhart » Logged

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

See also http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1228107706/0#0
(though it looks like your problem may be different.)
Logged

Austin, TX USA
Offline Offline
God Member
*****
Karma: 4
Posts: 997
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Good observation, westw.  It may be the same problem, since the main difference in ahoeben's implementation and mine is that his uses PGM_P, which maps indirectly to prog_char.

Mikal
Logged

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

I was wrong about my code working in 0012. The last version it worked with as posted is 0011, so it does seem to be the same issue as posted by westfw.

Between 0011 and 0012, newer versions of avr-gcc (4.3.0) and avr-libc (1.6) were included. Some more about the issue here:
http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&p=515844#515844

With Mikal's changes, I can confirm the code works with 0013. So there seems to be a workaround. Yay!

This page should probably be updated to reflect this workaround:
http://www.arduino.cc/en/Reference/PROGMEM
« Last Edit: February 25, 2009, 07:35:58 am by ahoeben » Logged

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 267
dinosaur cork
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I changed the docs a bit.

Can someone have a go at recommending which form for variable declarations we should recommend to users


dataType variableName[] PROGMEM = {};    // eenie
dataType PROGMEM variableName[] = {};    // meenie, minie
PROGMEM  dataType  variableName[] = {};  // mo

From the discussion, seems like form 3 should be the current form.

******************

Please note that PROGMEM is not part of the Arduino language and disseminating this information throughout the Arduino community should be done at your own risk.
Logged

Pages: [1]   Go Up
Jump to: