Society of Robots - Robot Forum
Software => Software => Topic started by: BANE on April 16, 2011, 12:16:38 PM
-
Hello all,
just try to get my feet wet with reading/writing to my Axon II's eeprom. Ive read all of webbots info (not sure if i understand it all yet, but hopefully will) and im getting some warning from AVR studio.
here is just the parts of code involving eeprom
//eeprom store var
int x_max_position;
//write to eeprom
x_max_position=10;
eeprom_write_byte(x_max_position, left_joy_x_max);
//display
rprintf("XMP=%d",eeprom_read_byte(x_max_position));
it gives me a warning saying:
warning: passing argument 1 of 'eeprom_write_byte' makes pointer from integer without a cast
also, returns the value 0, not 10
I read about having to include "EEMEM" in the variable but the compiler doesnt like it :P
Can anybody see my error? probably syntax error
thanks,
-
You definitely need the EEMEM in the variable definition.
If the compiler doesn't like it then you probably dont have
#include <avr/eeprom.h>
-
Ok, ive include that avr/eeprom but I still dont understand how to include EEMEM in the variables definition
uint8_t EEMEM x_max_position; AVR studio says
error: section attribute cannot be specified for local variables
here is the new code:
#include <avr/eeprom.h>
uint8_t EEMEM x_max_position;
eeprom_write_byte(x_max_position, 10);
rprintf("XMP=%d",eeprom_read_byte(x_max_position));
-
I'm guessing that you are trying to do it wit a variable that is defined inside a function - which is a no no. It must be a global variable.
ie
#include <avr/eeprom.h>
uint8_t EEMEM globalVar; // Should be ok
void foobar(void){
uint8_t EEMEM localVar; // Probably gives your error and cannot work
}
The difference is that 'globalVar' will always exist at the same memory location whereas 'localVar' comes and goes and is only valid whilst 'foobar' is running so can have a different memory slot every time its called.
-
ahhh i now know that global variables are :D
However, im still getting the two same warnings and every time i read and i get 255 not 10
#include <avr/eeprom.h>
uint8_t EEMEM x_max_position;
TICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart) {
eeprom_write_byte(x_max_position, 10);
rprintf("LJM=%d",eeprom_read_byte(x_max_position));
return 0;
Can i use x_max_position like this inside TICK_COUNT?
}
-
when you compile your program you will be getting warning errors like this:
warning: passing argument 1 of '__eewr_byte_m640' makes pointer from integer without a cast
This is because you should be passing the address of your variable - not the contents of the variable - ie it should be prefixed with an '&' symbol. So try changing your code to this:-
#include <avr/eeprom.h>
uint8_t EEMEM x_max_position;
TICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart) {
eeprom_write_byte(&x_max_position, 10);
rprintf("LJM=%d",eeprom_read_byte(&x_max_position));
return 0;
C is a real pain with this stuff - and its made worse by the avr-gcc compiler just issuing them as warnings rather than errors.
-
yep that little "&" made all the difference :D
helpful+1
thanks a ton
-
This is because you should be passing the address of your variable - not the contents of the variable - ie it should be prefixed with an '&' symbol.
Yep, this is called a 'pointer'.
For a better understanding see the K&R C book.
http://en.wikipedia.org/wiki/The_C_Programming_Language (http://en.wikipedia.org/wiki/The_C_Programming_Language)
http://www.amazon.com/Programming-Language-2nd-Brian-Kernighan/dp/0131103628 (http://www.amazon.com/Programming-Language-2nd-Brian-Kernighan/dp/0131103628)