Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
Torby
PostPosted: May 19, 2012 - 02:04 AM
Raving lunatic


Joined: Nov 11, 2003
Posts: 4040
Location: Chicago Illinois USA

I moved my ram wasting strings to program memory, but now my LCD speaks Borg. I must be picking the chars out of progmem improperly. I have this in a .CPP file, not a .C. Perhaps I need to follow a different tutorial?

http://www.avrfreaks.net/index.php?name ... sh+strings

My Write procedure:
Code:

void LCDWrite( char d )
{
   Wait();
   PORTD = PORTD | RSpin;
   lcdByte(d);   
   SetUS(37);
}


And my WritesP procedure:
Code:

void LCDWritesP(const char *FlashSTR)
{
      while (pgm_read_byte(FlashSTR) != 0x00)
      LCDWrite(pgm_read_byte(FlashSTR++));
}


And my Heavens to Mergatroid procedure:
Code:

void HeavensToMergatroid(void)
{
   char Heavens[] PROGMEM = "Heavens to";
   char Mergatroid[] PROGMEM = "Mergatroid!";
   LCDHome();
   LCDWritesP(Heavens);
   LCDxy(0,1);
   LCDWritesP(Mergatroid);
}


Let me try putting it back to ramwasting mode to see that I've not goofed something else up. Nope. It says its piece in plain English.

One thing I notice... When I first put it to ramwasting with:

Code:

LCDWrites("Heavens");
LCDXY(0,1(;
LCDWrites("Mergatroid");


The compiler reported 29 bytes of ram used. But when I take this out in favor of the progmem solution, the compiler still reports 29 bytes. This makes me wonder if I successfully got the data into flash, or is it still copying it to ram then looking for it the wrong place...

Exit stage left!

(I see I've been spelling Mergatroyd wrong. That must be the problem.)

_________________
Discursive design,

Torby

Some days, it's just not worth chewing through the restraints.
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
larryvc
PostPosted: May 19, 2012 - 02:11 AM
Raving lunatic


Joined: Dec 06, 2007
Posts: 2512
Location: Redmond, WA USA

This one's for you Torby:

http://www.phrases.org.uk/meanings/heav ... troyd.html

_________________
Larry

Those afraid to embrace the future will quickly fade into the past. - larryvc
 
 View user's profile Send private message  
Reply with quote Back to top
ezharkov
PostPosted: May 19, 2012 - 02:37 AM
Resident


Joined: Jun 21, 2005
Posts: 894
Location: Chicago area, USA

Code:

void HeavensToMergatroid(void)
{
   char Heavens[] PROGMEM = "Heavens to";
Do you get any compiler warnings? Never ignore them! You need to define this "static".
 
 View user's profile Send private message  
Reply with quote Back to top
Koshchi
PostPosted: May 19, 2012 - 03:26 AM
10k+ Postman


Joined: Nov 17, 2004
Posts: 13956
Location: Vancouver, BC

Quote:
You need to define this "static".
Or make them global.

_________________
Regards,
Steve A.

The Board helps those that help themselves.
 
 View user's profile Send private message  
Reply with quote Back to top
Torby
PostPosted: May 19, 2012 - 12:12 PM
Raving lunatic


Joined: Nov 11, 2003
Posts: 4040
Location: Chicago Illinois USA

1. Yes, I was thinking of Snagglepuss. Hence the "Exit stage left."

2. Didn't get any compiler warnings. I consider those as bad as errors so I get rid of them whenever I see them.

3. Static or Global.. Now that makes sense.

Now my ram use is 3 bytes, my thing no longer speaks Borg and Murgatroyd is spelled correctly.

So which cartoon character was always saying, "That's what I always say sometimes"?

_________________
Discursive design,

Torby

Some days, it's just not worth chewing through the restraints.
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
Torby
PostPosted: May 19, 2012 - 12:26 PM
Raving lunatic


Joined: Nov 11, 2003
Posts: 4040
Location: Chicago Illinois USA

Wally Gator.

_________________
Discursive design,

Torby

Some days, it's just not worth chewing through the restraints.
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
clawson
PostPosted: May 19, 2012 - 12:45 PM
10k+ Postman


Joined: Jul 18, 2005
Posts: 62940
Location: (using avr-gcc in) Finchingfield, Essex, England

Didn't get a warning? Surely there was one about progmem attribute being ignored? Which version of AVR-GCC is this?

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
abcminiuser
PostPosted: May 19, 2012 - 02:56 PM
Moderator


Joined: Jan 23, 2004
Posts: 9878
Location: Trondheim, Norway

You should actually also get a warning or error that PROGMEM variables need to be marked as "const" - at least, in the version of avr-gcc shipped with Atmel Studio 6.

- Dean Twisted Evil

_________________
Atmel Studio 6.1 is now released, grab it here.
Report AS6/ASF bugs here.
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
SprinterSB
PostPosted: May 19, 2012 - 04:37 PM
Posting Freak


Joined: Dec 21, 2006
Posts: 1547
Location: Saar-Lor-Lux

Maybe you hit PR34734, fixed in 4.6.2. If so, use a section attribute as work-around.
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
Torby
PostPosted: May 20, 2012 - 02:11 AM
Raving lunatic


Joined: Nov 11, 2003
Posts: 4040
Location: Chicago Illinois USA

Sounds like the opposite of that bug. I do get lots of warnings being ADD, typing on a netbook keyboard, and generally not knowing C very well. So when I get them, I figure out what it's complaining about and correct until I get no warnings.

However! I just had an
Code:
if (J=0)


which, of course should have been (J==0) and didn't get a warning. I was just left to wonder why the simulator bounced around with no rhyme or reason till I saw it and corrected it.

Tonight's experiment successful. I now know how my hall sensor responds to the magnet in different orientations.

Odd.. one of my tiny neodymium magnets has split open and spilled brown magnetic dust all over the others. Didn't know they'd do that. Maybe I have poor ones.

_________________
Discursive design,

Torby

Some days, it's just not worth chewing through the restraints.
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
ezharkov
PostPosted: May 20, 2012 - 11:34 AM
Resident


Joined: Jun 21, 2005
Posts: 894
Location: Chicago area, USA

Torby wrote:
which, of course should have been (J==0) and didn't get a warning
Do you have -Wall on your command line? (I normally use -Wextra -Wstrict-prototypes -Wundef -Wall -Werror)
 
 View user's profile Send private message  
Reply with quote Back to top
SprinterSB
PostPosted: May 20, 2012 - 06:43 PM
Posting Freak


Joined: Dec 21, 2006
Posts: 1547
Location: Saar-Lor-Lux

Torby wrote:
Code:
if (J=0)
which, of course should have been (J==0) and didn't get a warning.
Just turn on warnings and you get:
Code:
warning: suggest parentheses around assignment used as truth value
Tested with avr-gcc 3.4, 4.2, 4.3, 4.5, 4.6 and 4.7.

If you don't want a warning for such an assignment, write
Code:
if ((J=0))
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
Torby
PostPosted: May 21, 2012 - 04:16 PM
Raving lunatic


Joined: Nov 11, 2003
Posts: 4040
Location: Chicago Illinois USA

Well, I usually see that warning and change it to ==. Almost always type it wrong to start.

As far as what teh command line says, I haven't a clue. Studio 6 does that.

_________________
Discursive design,

Torby

Some days, it's just not worth chewing through the restraints.
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
wek
PostPosted: May 21, 2012 - 04:50 PM
Raving lunatic


Joined: Dec 16, 2005
Posts: 3095
Location: Bratislava, Slovakia

SprinterSB wrote:
If you don't want a warning for such an assignment, write
Code:
if ((J=0))
If you don't want a warning for such an assignment, you should consult your psychiatrist... Wink

JW
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
jldsystems
PostPosted: May 21, 2012 - 05:07 PM
Hangaround


Joined: Oct 26, 2002
Posts: 159
Location: Lancaster PA

That's why I typically write

Code:
if (0==j)


Then if I drop = I get an error, although admittedly, it is harder to read.

_________________
Jeff Dombach, JLD Systems
"We do the stuff behind the buttons!"
Your source for embedded solutions with a 100% Guarantee.
http://www.jldsystems.com
Phone 717.892.1100
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
Torby
PostPosted: May 21, 2012 - 06:01 PM
Raving lunatic


Joined: Nov 11, 2003
Posts: 4040
Location: Chicago Illinois USA

I just edited out the correct extra = sign, and it did give me a warning, just didn't switch the tab at the bottom so I didn't notice it.

What do I typically write? Errors! That's why I rely on the warning list

_________________
Discursive design,

Torby

Some days, it's just not worth chewing through the restraints.
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
clawson
PostPosted: May 21, 2012 - 06:51 PM
10k+ Postman


Joined: Jul 18, 2005
Posts: 62940
Location: (using avr-gcc in) Finchingfield, Essex, England

Use -Werror then all warnings become errors and simply cannot be ignored.

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
Torby
PostPosted: May 21, 2012 - 10:43 PM
Raving lunatic


Joined: Nov 11, 2003
Posts: 4040
Location: Chicago Illinois USA

How do you tell Studio 6 to add -Werror?

_________________
Discursive design,

Torby

Some days, it's just not worth chewing through the restraints.
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
ChaunceyGardiner
PostPosted: May 21, 2012 - 10:51 PM
Posting Freak


Joined: Mar 09, 2012
Posts: 1452
Location: North Carolina, USA

Torby wrote:
How do you tell Studio 6 to add -Werror?


Rightclick on your project in the solution explorer.
Select [Properties].
Select [Toolchain].
Select [AVR/GNU C compiler]/[Warnings].
Check [Warnings as errors].

You may want to set [Configuration] to [All Configurations] before you change this compiler option.
 
 View user's profile Send private message  
Reply with quote Back to top
Torby
PostPosted: May 22, 2012 - 12:32 AM
Raving lunatic


Joined: Nov 11, 2003
Posts: 4040
Location: Chicago Illinois USA

Done and tried. Thanks.

_________________
Discursive design,

Torby

Some days, it's just not worth chewing through the restraints.
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
Frisky
PostPosted: May 22, 2012 - 03:03 AM
Rookie


Joined: Sep 29, 2002
Posts: 31
Location: Chicago,Il USA

I'm using WinAVR with Programmer's Notepad how can I select Warning are errors mode. Would it be an option in the make file?
Thanks
Don
 
 View user's profile Send private message  
Reply with quote Back to top
larryvc
PostPosted: May 22, 2012 - 03:50 AM
Raving lunatic


Joined: Dec 06, 2007
Posts: 2512
Location: Redmond, WA USA

I'm not familiar with Programmers Notepad but if the makefile calls avr-gcc.exe then just add -Werror to the line that invokes the compiler.

It's probably better if you can post the makefile, or the lines that call avr-gcc.exe, just to check.

_________________
Larry

Those afraid to embrace the future will quickly fade into the past. - larryvc
 
 View user's profile Send private message  
Reply with quote Back to top
JohanEkdahl
PostPosted: May 22, 2012 - 08:58 AM
10k+ Postman


Joined: Mar 27, 2002
Posts: 18756
Location: Lund, Sweden

Quote:

I'm using WinAVR with Programmer's Notepad how can I select Warning are errors mode. Would it be an option in the make file?

Yes.

Details depends on the makefile you use.
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
Torby
PostPosted: May 28, 2012 - 04:58 PM
Raving lunatic


Joined: Nov 11, 2003
Posts: 4040
Location: Chicago Illinois USA

Now I'm trying to put the array of pointers in progmem:

Code:


const char Scale0[] PROGMEM = "1:20.3";
const char Scale1[] PROGMEM = "1:22";
const char Scale2[] PROGMEM = "1:24";
const char Scale3[] PROGMEM = "1:29";
const char Scale4[] PROGMEM = "1:32";
char* ScaleText [] PROGMEM = { Scale0, Scale1, Scale2, Scale3, Scale4};


But the compiler says ScaleText has to be constant. So I add const:

Code:


const char Scale0[] PROGMEM = "1:20.3";
const char Scale1[] PROGMEM = "1:22";
const char Scale2[] PROGMEM = "1:24";
const char Scale3[] PROGMEM = "1:29";
const char Scale4[] PROGMEM = "1:32";
const char* ScaleText [] PROGMEM = { Scale0, Scale1, Scale2, Scale3, Scale4};


But winavr still complains that ScaleText has to be constant to put in program memory. I tried telling it, but it just doesn't understand me.

Off to Memorializing activities with me! I'm the first disqualified of a long line of army veterans. (After I get the code tags right.)

_________________
Discursive design,

Torby

Some days, it's just not worth chewing through the restraints.
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
wek
PostPosted: May 28, 2012 - 05:01 PM
Raving lunatic


Joined: Dec 16, 2005
Posts: 3095
Location: Bratislava, Slovakia

Code:
const char* const ScaleText [] PROGMEM = { Scale0, Scale1, Scale2, Scale3, Scale4};

The first const says, you are pointing to a variable which is not going to change. The second const says that the pointer is not going to change either.

JW
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
JohanEkdahl
PostPosted: May 28, 2012 - 05:21 PM
10k+ Postman


Joined: Mar 27, 2002
Posts: 18756
Location: Lund, Sweden

Put
explain const char* const ScaleText []
into a Cdecl online server.

Then play around a bit, remove and add "const" at different places.
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
wek
PostPosted: May 28, 2012 - 05:32 PM
Raving lunatic


Joined: Dec 16, 2005
Posts: 3095
Location: Bratislava, Slovakia

JohanEkdahl wrote:
I am not the only C-Hater, then?

JW
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
larryvc
PostPosted: May 28, 2012 - 05:34 PM
Raving lunatic


Joined: Dec 06, 2007
Posts: 2512
Location: Redmond, WA USA

JohanEkdahl wrote:
Put
explain const char* const ScaleText []
into a Cdecl online server.

Then play around a bit, remove and add "const" at different places.

Wow, Johan, you've given me a tool I didn't know about. Thank you for this post. Smile

_________________
Larry

Those afraid to embrace the future will quickly fade into the past. - larryvc
 
 View user's profile Send private message  
Reply with quote Back to top
JohanEkdahl
PostPosted: May 28, 2012 - 05:49 PM
10k+ Postman


Joined: Mar 27, 2002
Posts: 18756
Location: Lund, Sweden

Chances are you actually have a commald-line based cdecl on your hard drive..
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
larryvc
PostPosted: May 28, 2012 - 06:16 PM
Raving lunatic


Joined: Dec 06, 2007
Posts: 2512
Location: Redmond, WA USA

JohanEkdahl wrote:
Chances are you actually have a commald-line based cdecl on your hard drive..

Maybe in one of my linux VMs, not on any of my hard drives and there is a ton of historic, read "very old and useless", stuff there. Is there a version that will run from from the command line or powershell that is compatible with Win7, or do I need cygwin or something like that?

_________________
Larry

Those afraid to embrace the future will quickly fade into the past. - larryvc
 
 View user's profile Send private message  
Reply with quote Back to top
sternst
PostPosted: May 28, 2012 - 06:23 PM
Raving lunatic


Joined: Jul 23, 2001
Posts: 2470
Location: Osnabrueck, Germany

larryvc wrote:
Wow, Johan, you've given me a tool I didn't know about. Thank you for this post. Smile
But keep in mind that it is not always correct.
E.g.
int volatile i; -> syntax error

_________________
Stefan Ernst
 
 View user's profile Send private message  
Reply with quote Back to top
larryvc
PostPosted: May 28, 2012 - 07:07 PM
Raving lunatic


Joined: Dec 06, 2007
Posts: 2512
Location: Redmond, WA USA

sternst wrote:
But keep in mind that it is not always correct.
E.g.
int volatile i; -> syntax error

But it does work as this:

volatile int i; -> declare i as volatile int

_________________
Larry

Those afraid to embrace the future will quickly fade into the past. - larryvc
 
 View user's profile Send private message  
Reply with quote Back to top
sternst
PostPosted: May 28, 2012 - 07:25 PM
Raving lunatic


Joined: Jul 23, 2001
Posts: 2470
Location: Osnabrueck, Germany

larryvc wrote:
But it does work as this:

volatile int i; -> declare i as volatile int
So what? That does not change the fact that the response to "int volatile i;" is wrong.

_________________
Stefan Ernst
 
 View user's profile Send private message  
Reply with quote Back to top
JohanEkdahl
PostPosted: May 28, 2012 - 07:51 PM
10k+ Postman


Joined: Mar 27, 2002
Posts: 18756
Location: Lund, Sweden

Quote:

Maybe in one of my linux VMs

Darn, I had a clear memory of that it actually came with the WinAVR installation, but no..

Then it must have been that I downloaded the source and built it. In Visual Studio. (I.e. no CygWin, no MinGW).
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
snigelen
PostPosted: May 28, 2012 - 08:04 PM
Posting Freak


Joined: Jan 08, 2009
Posts: 1199
Location: Lund, Sweden

As clawson said recently,
Code:
sudo apt-get install cutils
if you're using something like debian or ubuntu.
 
 View user's profile Send private message  
Reply with quote Back to top
larryvc
PostPosted: May 28, 2012 - 08:14 PM
Raving lunatic


Joined: Dec 06, 2007
Posts: 2512
Location: Redmond, WA USA

Yeah, I was looking for one in windows as mentioned above.

Thanks anyways. Smile

_________________
Larry

Those afraid to embrace the future will quickly fade into the past. - larryvc
 
 View user's profile Send private message  
Reply with quote Back to top
snigelen
PostPosted: May 28, 2012 - 08:24 PM
Posting Freak


Joined: Jan 08, 2009
Posts: 1199
Location: Lund, Sweden

Yes, I realize that now, I read too fast,
Quote:
Maybe in one of my linux VMs
I thought that meant that you looked there and didn't find it. I now see that you probably meant "It may be there, but I want a Windows version".
 
 View user's profile Send private message  
Reply with quote Back to top
Torby
PostPosted: May 29, 2012 - 12:17 AM
Raving lunatic


Joined: Nov 11, 2003
Posts: 4040
Location: Chicago Illinois USA

Wow, at the speed of light, from far away Slovakia, the answer comes while I'm out playing with trains in a beautiful garden. Now the compiler is happy. Wonder if the silly program works. Oh, still need to....

(I'm not really hot on C either, but the world abandoned Pascal and Modula years ago.)

_________________
Discursive design,

Torby

Some days, it's just not worth chewing through the restraints.
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
larryvc
PostPosted: May 30, 2012 - 07:28 PM
Raving lunatic


Joined: Dec 06, 2007
Posts: 2512
Location: Redmond, WA USA

sternst wrote:
larryvc wrote:
But it does work as this:

volatile int i; -> declare i as volatile int
So what? That does not change the fact that the response to "int volatile i;" is wrong.

Sorry Stefan, I missed this.

I really meant to say that it worked for one and not the other. I was not questioning your statement above as I agree with it.

_________________
Larry

Those afraid to embrace the future will quickly fade into the past. - larryvc
 
 View user's profile Send private message  
Reply with quote Back to top
Torby
PostPosted: May 31, 2012 - 02:47 PM
Raving lunatic


Joined: Nov 11, 2003
Posts: 4040
Location: Chicago Illinois USA

No! I don't want to read this! I'll be putting "volatile" in the wrong place for the rest of my life!

_________________
Discursive design,

Torby

Some days, it's just not worth chewing through the restraints.
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits