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
abcminiuser
PostPosted: Jul 17, 2006 - 10:44 PM
Moderator


Joined: Jan 23, 2004
Posts: 7028
Location: Melbourne, Victoria, Australia

Excellent, but do remember that the "double" data type does not exist in GCC at present. It is currently a direct alias to the "float" data type.

- Dean Twisted Evil

_________________

 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
cemox
PostPosted: Jul 18, 2006 - 06:11 AM
Rookie


Joined: Sep 24, 2004
Posts: 24
Location: Istanbul, Turkey

Yes, you are right. The reason why I habitually use double instead of float is that printf produces a warning when printing a float variable with %f format specifier.

I mean, something like this

Code:
float a;
printf("Variable a = %3.2f",a);


causes the compiler warning

Code:
warning: double format, float arg (arg 2)


I think the correct way, as you pointed out, is to use the float data type and cast it to double when using it with printf in order to get rid of the compiler warning.

Code:
printf("Variable a = %3.2f",(double)a);


So, one can replace all the double's with float's in the examples in my previous post.

Cheers,

Cemo
 
 View user's profile Send private message  
Reply with quote Back to top
twadepgh
PostPosted: Jul 19, 2006 - 01:33 AM
Newbie


Joined: Jul 18, 2006
Posts: 9


The only thing I'd say to writing structures out to EEPROM like this is that it implies that you have the RAM space available to create an image of what's in EEPROM. On the other hand, if you have a large number of say, configuration variables that you want to store in EEPROM, storing them individually or dereferencing each element of a structure seems like it could save some RAM... Can't say from direct experience, but that's how it looks to me.
 
 View user's profile Send private message  
Reply with quote Back to top
abcminiuser
PostPosted: Jul 19, 2006 - 05:12 AM
Moderator


Joined: Jan 23, 2004
Posts: 7028
Location: Melbourne, Victoria, Australia

I personally have all my EEPROM variables inside a single stuct, named EEPROMVars. This allows me to very easily tell which variables are in EEPROM or not, and has not discernable effect on performance. I only read out variables one at a time which means that no extra RAM is wasted.

- Dean Twisted Evil

_________________

 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
JulianHigginson
PostPosted: Aug 08, 2006 - 08:13 AM
Hangaround


Joined: Aug 16, 2005
Posts: 301


excellent tutorial!
one problem - I can't seem to use the EEMEM directive.
I get compile errors.

yes, I'm including the eeprom.h
and yes, basic eeprom read and write commands are working if I don't use the EEMEM directive.

I thought I had the latest version of winavr and avrstudio installed, but maybe not? can you please specify what install version of winavr you wrote this code for? (and avr-libc if necessary?) thanks!

this might also come in handy in a couple of years if newer versions of winavr don't work with this syntax.
 
 View user's profile Send private message  
Reply with quote Back to top
abcminiuser
PostPosted: Aug 08, 2006 - 08:20 AM
Moderator


Joined: Jan 23, 2004
Posts: 7028
Location: Melbourne, Victoria, Australia

I am using AVRLibC 1.4.4 for my tutorial, and WinAVR 20060421 - the latest released version.

If the EEMEM macro is not present in your EEPROM.h header file, then you can add it manually:

Code:
#define EEMEM __attribute__((section(".eeprom")))


In my current header file it is also available under the macro name "EEPROM". I'm not sure if this was present in earlier versions - does changing the "EEMEM" instances to "EEPROM" fix your problem?

- Dean Twisted Evil

_________________

 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
JulianHigginson
PostPosted: Aug 08, 2006 - 08:35 AM
Hangaround


Joined: Aug 16, 2005
Posts: 301


cool!

yeah.. turns out I had winavr20050215 installed.
Embarassed
I should probably read these forums more often so I'm up to date with everything that happens.

the earlier eeprom.h doesn't have a #define for EEPROM either.
adding the define for EEMEM in the main code listing worked.


I downloaded the new winavr now.
will have a bash at installing it next.


thankyou so much!
 
 View user's profile Send private message  
Reply with quote Back to top
anhinga
PostPosted: Sep 26, 2006 - 02:49 AM
Newbie


Joined: Jul 18, 2002
Posts: 1


Many Many Many thanks to you! I was dreading learning how to access the eeprom, and you summed it up just right. I was able to figgure it out in just an hour or two! Again, thank you so much!
 
 View user's profile Send private message  
Reply with quote Back to top
abcminiuser
PostPosted: Sep 26, 2006 - 02:52 AM
Moderator


Joined: Jan 23, 2004
Posts: 7028
Location: Melbourne, Victoria, Australia

No problem - glad I could help!

Best of luck to you in your projects.

- Dean Twisted Evil

_________________

 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
aliasgherman
PostPosted: Apr 02, 2007 - 09:45 AM
Newbie


Joined: Apr 02, 2007
Posts: 8


16 bit address but 8 bit data

For example I want to read the byte at address 260 of my EEPROM (ATMega8515).

Now I can't use (uint8_t *) as an address pointer as address is not in 8-bits.

Also I can't eeprom_read_word because it treats the address as two addresses for two 8-bit data locations.

I need a function like this
eeprom_read_byte ( (uint16_t *) 260 )

Please tell me how to work around this problem. You can reply me at my e-mail address
aliasgherman@yahoo.com

Thankyou,

Ali Asgher Mansoor Habiby[/b]
 
 View user's profile Send private message  
Reply with quote Back to top
abcminiuser
PostPosted: Apr 02, 2007 - 09:51 AM
Moderator


Joined: Jan 23, 2004
Posts: 7028
Location: Melbourne, Victoria, Australia

Quote:

You can reply me at my e-mail address
aliasgherman@yahoo.com


I could, but I wont. If you have a question I'll answer it here so I can help others. Whether or not you'll put in the effort to read what I have gone through the effort of writing is up to you.


Writing and reading ints is easy, if you read the entire tutorial Wink. What you're after is the eeprom_*_word routines:

Quote:
Our second variable is an int, so we need the eeprom_read_word routine:

Code:
#include <avr/eeprom.h>

uint8_t  EEMEM NonVolatileChar;
uint16_t EEMEM NonVolatileInt;
uint8_t  EEMEM NonVolatileString[10];

int main(void)
{
    uint8_t  SRAMchar;
    uint16_t SRAMint;

    SRAMchar = eeprom_read_byte(&NonVolatileChar);
    SRAMint  = eeprom_read_word(&NonVolatileInt);
}


- Dean Twisted Evil

_________________

 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
muzzkat
PostPosted: May 04, 2007 - 04:51 AM
Newbie


Joined: Mar 13, 2006
Posts: 19


Thanks for the tutorial.

Does anyone know how i can get the compile to create a eeprom file of initial values if i use fixed address?

I know this code works:

Code:
uint8_t EEMEM SomeVariable = 12;


but i need to use fixed address as i need to preserve EEPROM values after a flash update (via bootloader). aka if i use the above code i can not guarantee that the compile will pick the same location in the new firmware version.

Let me know if i need to explain..

Cheers

Murray
 
 View user's profile Send private message  
Reply with quote Back to top
clawson
PostPosted: May 04, 2007 - 10:34 AM
10k+ Postman


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

Murray,

Maybe put all your EEPROM variables into a single struct{} so you can determine the positioning. For example:
Code:
typedef struct {
 int fred;
 char c;
 long bob ;
} struct_t;

struct_t EEMEM my_struct = { 37, 'a', 12345678 };

produces a .eep file:
Code:
:070000002500614E61BC0008
:00000001FF

in which the 37 (0x25), 'a' (0x61) and 12345678 (0xBC614E) are in known positions.

Cliff

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
AllN
PostPosted: May 04, 2007 - 05:52 PM
Posting Freak


Joined: Feb 14, 2007
Posts: 1858
Location: San Diego California

Yeaaaa Dean!!!! “The Author”
Looks like 1/3 of the memory chapter of a very good book, to the rest of us at least!
Reads like you’re an author, looks like you took the time to write like an author, seems like your eager audience is awaiting your next chapter, to me.
Consider this life observation of two men with the same life span.
Both lifelong labors create only one indicial functioning commercial program that sells 500k copies to its intended vertical market.
But one man is much richer from the same effort in life. Why?
Because, becoming rich is accruing a different state of mine.
While they were both working on the project only one was selling every part he could during development. He wrote several books (from his notes) on each topic he learned throughout his life. He sold several new small programs. Created from the various parts of the main program like the same multi-media routines for family photo albums. He sold his programs security registration routines to other programmers including the other man in this story.
When no one was willing to pay the price he cut the price in half not stopping at zero like most in life would. No, he would give it away for free! PLUS $15.00 shipping and handling and made several thousand dollars from a program no one would pay for.

Warning, becoming rich is accruing a marketing state of mine.
It would be so easy to turn these Tut’s into a very good book that will produce extra income for life with the same labor.

Sorry it’s my job to aspire people to become rich, as they might then be able to loan me some money.
Cheers,
John
 
 View user's profile Send private message  
Reply with quote Back to top
abcminiuser
PostPosted: May 06, 2007 - 01:49 PM
Moderator


Joined: Jan 23, 2004
Posts: 7028
Location: Melbourne, Victoria, Australia

Cheers John!

I sadly don't have the talent to write a book of my own - Smokey possesses what I do not. I've become quite adept at writing specific tutorials, but I just can't seem to "glue" them all together into one big book.

Nice story - selling the parts is a good idea! Now, if only I received a $1 donation for each reader of each of my tutorials Wink.

I don't mind giving away my time for free for the community. If I'm doing specific work for an individual/company I do charge (a modest amount), but since I have a choice to contribute here, contributing is its own reward.

- Dean Twisted Evil

EDIT: And I also enjoy all the kudos writing stuff for free brings! Wink

_________________

 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
AllN
PostPosted: May 06, 2007 - 05:30 PM
Posting Freak


Joined: Feb 14, 2007
Posts: 1858
Location: San Diego California

abcminiuser wrote:
Cheers John!

I sadly don't have the talent to write a book of my own - Smokey possesses what I do not. I've become quite adept at writing specific tutorials, but I just can't seem to "glue" them all together into one big book.
...

Ask the forum if they agree with your assessment of not having the talent. Currently you are transitioning different subjects within your Tut’s. You will learn how to transition chapters too. Plus, are you kidding most the stuff I have to read they just say “Now I need to change the subject because you need to know this next”. Not much of a transition required with technical writing as the author is just boring me with his transition story anyway. I just want to know how.
All I'm saying is consider saving your work and make plans to turn it into a revenue stream in your future. You will get better (more confidence is all you need now) and continue learning and it will become easier with each Tut you write. Self-doubt is the biggest excuse people use not to try. (and laziness – You don’t have that!)
It doesn’t have to be much of a book to make you money. Remember Chernobyl nuclear plant accident. Within the week a 30 page ‘book’ was written on how to protect your family from fallout. The author had wanted to know how to protect is family and then sold his labor as a 30 page ‘book’ for $12.00 with a money back guarantee. He placed adds in a small weekly local publications in cities within 100 miles of every nuclear plant in the US. $2,100 in advertising made $18,000 in 5 months. Here’s a secret American’s won’t take the time to return anything for less than $15.00 to $25.00.
It’s planning and marketing that makes you easy money in life. Not perfect writing.
Cheers,
John

_________________
Resistance is futile…… You will be compiled!
 
 View user's profile Send private message  
Reply with quote Back to top
alex_weber
PostPosted: Jun 19, 2007 - 08:09 AM
Newbie


Joined: Dec 18, 2006
Posts: 6


Hi Dean,

thanks for this great tutorial, it helped a lot.

I think I found another small bug:
Code:

#include <avr/eeprom.h>

uint8_t  EEMEM NonVolatileChar;
uint16_t EEMEM NonVolatileInt;
uint8_t  EEMEM NonVolatileString[10];

int main(void)
{
    uint8_t  SRAMchar;
    uint16_t SRAMint;
    uint8_t  SRAMstring;   

    SRAMchar = eeprom_read_byte(&NonVolatileChar);
    SRAMint  = eeprom_read_word(&NonVolatileInt);
    eeprom_read_block((void*)&SRAMstring, (const void*)&NonVolatileString, 10);
}


Shouldn't it be like this?
Code:

    uint8_t  SRAMstring[10];   


Kind regards,
Alex
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
abcminiuser
PostPosted: Jun 19, 2007 - 01:56 PM
Moderator


Joined: Jan 23, 2004
Posts: 7028
Location: Melbourne, Victoria, Australia

Yes it should, good catch. I'll correct that now.

- Dean Twisted Evil

_________________

 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
thecolororange
PostPosted: Jul 21, 2007 - 10:07 PM
Newbie


Joined: May 22, 2007
Posts: 4


@abcminiuser:

You mentioned that you just read out the variables from EEPROM as you need them. I have some data that I am storing in the EEPROM, and I was debating whether to read it out as I need it, or read it into variables in RAM.

The data is being used in a loop that's running maybe every 100 ms or so. I'm not running out of SRAM or anything, but I also don't mind the 4 clock cycle delay caused by reading from the EEPROM. Anyone have any suggestions as to which way is better/more appropriate?
 
 View user's profile Send private message  
Reply with quote Back to top
abcminiuser
PostPosted: Jul 22, 2007 - 09:19 AM
Moderator


Joined: Jan 23, 2004
Posts: 7028
Location: Melbourne, Victoria, Australia

It's entirely up to you, if neither the increased RAM nor the increased fetch time is a problem. Reading from EEPROM does not wear out its lifespan, so whichever method you choose will be the one you deem most appropriate.

- Dean Twisted Evil

_________________

 
 View user's profile Send private message Send e-mail 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