Pages: [1]   Go Down
Author Topic: PROGMEM use in Arduino  (Read 1086 times)
0 Members and 1 Guest are viewing this topic.
Toronto, Canada
Offline Offline
Full Member
***
Karma: 0
Posts: 144
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I have a .h file with lots of entries like this:
Code:
static const char v1a[] PROGMEM="OUS_";
After several entries, there is an entry like this:
Code:
static const VOCAB PROGMEM s_vocab[] ={
      { v1a,  v1b} ,{ v2a,  v2b}, {  v3a,  v3b},{  v4a,  v4b},{  v5a,  v5b},{  v6a,  v6b},{  v7a,  v7b},{  v8a,  v8b},{  v9a,  v9b},{ v10a, v10b},..... and so on.... };
Then in the code, s_vocab is used.

When compiling, I get an error like this for every entry where PROGMEM is used:
Code:
C:\DOCUME~1\Gabi\LOCALS~1\Temp\build63463.tmp\/english.h:8: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'PROGMEM'

Then I get this error:
Code:
error: 's_vocab' undeclared (first use in this function) In function xxx

I have tried to make a library, but the s_vocab gets out of scope (I don't get the PROGMEM errors in this case).

Any advice would be very appreciate!

Thanks!
Logged


Toronto, Canada
Offline Offline
Full Member
***
Karma: 0
Posts: 144
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Fixed the original problem by reversing the position of the PROGMEM in the declaration, like this:
static const VOCAB s_vocab[] PROGMEM={...};

Now I have other errors.

In the  core.c file I have a struct like this:
Code:
typedef struct Vocab {
      const char* txt;
      const char* phoneme;
} VOCAB;

As I read about structs, I have a struct called Vocab with 2 members and an object VOCAB (I think...). Then, in the .h file I have the VOCAB declared as:

static const VOCAB s_vocab[] PROGMEM={....};

However, I get this error at compile:
Code:
C:\DOCUME~1\Gabi\LOCALS~1\Temp\build63463.tmp\/english.h:785: error: expected '=', ',', ';', 'asm' or '__attribute__' before 's_vocab'

If I add '=' like this:
static const VOCAB=s_vocab[] PROGMEM={....}

I get this errors:
Code:
C:\DOCUME~1\Gabi\LOCALS~1\Temp\build63463.tmp\/english.h:785: error: 's_vocab' undeclared here (not in a function)
C:\DOCUME~1\Gabi\LOCALS~1\Temp\build63463.tmp\/english.h:785: error: expected expression before ']' token
error: 'VOCAB' redeclared as different kind of symbolC:\DOCUME~1\Gabi\LOCALS~1\Temp\build63463.tmp\/english.h:785: error: previous definition of 'VOCAB' was here
and it highlights the end of the struct declaration in the .c file.

Any ideas how to fix this?

Thank you for any help!
Logged


Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 209
Posts: 13021
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I'd like to help but I'm having problems understanding what goes where.  Can you put together a small example that illustrates the problem?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 631
Posts: 50115
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
As I read about structs, I have a struct called Vocab with 2 members and an object VOCAB (I think...).

Not quite. You have a struct called Vocab with 2 members. You also have an alias for "struct Vocab" that is "VOCAB". This allows you to use "VOCAB" as the type where you would ordinarily have to use "struct Vocab" as the type.

It's a fairly conventional shorthand.

Can't help you on the rest of the questions/issues, though.
Logged

Toronto, Canada
Offline Offline
Full Member
***
Karma: 0
Posts: 144
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

OK. I have talked with the author of the original code I'm trying to implement in Arduino. He can't help with the Arduino part, but he gave me permission to post the code and ask questions here.

So here is the link to the original code (see the bottom of the page):
http://www.societyofrobots.com/member_tutorials/node/212

And here is my attempt to make it work in Arduino:
http://www.societyofrobots.com/member_tutorials/files/TTStest.zip

Any help would be greatly appreciated!
Logged


Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 209
Posts: 13021
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Brief: The header file english.h makes use of three types (VOCAB, PHONEME, and SOUND_INDEX).  These types are declared in core.c after the english.h file has been included.

Long: Essentially, the preprocessor starts with a source file (like core.c) and inserts the contents of each include file at the #include line.  In other words, english.h is inserted into core.c at the #include "english.h" line.  This puts the definitions of the three types after they are first referenced.

To solve the problem, I cut each type definition from "core.c" and pasted it at the top of "english.h"

Does that make sense?
Logged

Pages: [1]   Go Up
Jump to: