473,396 Members | 1,853 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

C-AVR programming and saving to epprom

so i started learning avr-c programming a few weeks ago and i'm a little confused about using the eeprom so save values.
i've been working a snake game for my project, and i need to save everything at any point to the eeprom so that the user can load it from that spot again.
but first i've been receiving warnings in regard to the way i've been trying to save the the highscore
Expand|Select|Wrap|Line Numbers
  1. #include <avr/eeprom.h> 
  2. eeprom_write_word(1, hiscore);
  3. printf("Current High-Score: %d\n", eeprom_read_word(1));
  4.  
those are the only 2 instances where i've actually written to eeprom so far.
and it works so far, without any problems to the game, but the problem is i've been getting warnings saying.
Expand|Select|Wrap|Line Numbers
  1. warning: passing argument 1 of 'eeprom_read_word' makes pointer from integer without a cast
  2.  
  3. warning: passing argument 1 of 'eeprom_write_word' makes pointer from integer without a cast
  4.  
and i don't know how to fix the code.
any help would be appreciated
thanks,
phoenix1990
Oct 19 '09 #1
3 4066
newb16
687 512MB
It wants cast? Ok, give it the cast -
eeprom_read_word((int*)1)
or something like, depending on declaration of eeprom_read_word.
Oct 19 '09 #2
Banfa
9,065 Expert Mod 8TB
@newb16
That is quite a bad mistake/assumption to make without further evidence that that is actually required. I know several people that had problems because they did that or something similar.

I think it is more likely that the function expected a pointer to a word(int) but you provided an int

Expand|Select|Wrap|Line Numbers
  1. const int *HIGHSCORE_ADDRESS = <someAddressInEEPROM>;
  2.  
  3. highscore = eeprom_read_word(HIGHSCORE_ADDRESS);
  4.  
The point is I suspect the function is expecting you to pass it a location in eeprom to save to, not a number cast to an address. Unless you were very very lucky (int *)1 is most unlikely to be an address in EEPROM.

OK I just Googled the AVR memory map and I take that back, it turns out that for AVR architecture (int *)1 is a valid EEPROM address. Which just goes to prove the point that you can't always generalise (particularly with micro-controllers) things that look dubious from a generalised Standard C point of view can be perfectly correct.

I would still recommend #defining (or using const ints) the locations of you stored parameters in EEPROM rather than hardcoding using magic numbers.
Oct 19 '09 #3
thanks for the help guys, your comments saved me a lot of time.
Oct 20 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Sam Fisher | last post by:
Hi @all I'm really new to programming, so please dont' lose patience. Now, I'm writing a VB .net application in which (as in most apps) the user shall setup a configuration (via checkboxes etc.)....
7
by: Philipp Lenssen | last post by:
How do I load and save a UTF-8 document in XML in ASP/VBS? Well, the loading* is not the problem actually -- the file is in UTF-8, and understood correctly -- but once saved, the UTF-8 is...
2
by: Roy Gourgi | last post by:
Hi, Is it possible to save to a database as opposed to saving to a flat .txt file? It could be any database program, such as FoxPro (preferably), SQL Server, MySQL. Furthermore, I would also...
0
by: soberhi | last post by:
I am new to Access (and Access programming) so kindly be gentle. I did try to search around before asking this question. I am simplifying my problem in the hopes that this scaled down version...
28
by: marcpirat | last post by:
hi we create a real-time program on a embedded linux system. the program will run a few time by second i would like to know if it's better to create global variable or create the variable in...
1
by: Dev | last post by:
Dear Friends, I am passing the image name, size (in bytes) and imgaeformat (like jpg or bmp or pdf) through the network. I want display the image into picturebox without saving image...
3
by: cdj | last post by:
Hi all, I've got a picturebox on a form, and a save button. When I go to save, the app craps out with the following error: ================== An unhandled exception of type...
0
by: Shiran | last post by:
hi, i'm programming in ASP.net and i'm having a problem saving the state of the session. all the parameters i save , primitive or not are not being save and get lost. does anybody have any...
15
by: Dan DeConinck | last post by:
Hello, I want to save the position of all the controls on my form. I would like to write them out to a preference file. I have done this in DOS BASIC like this: TO WRITE the preference...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.