NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.
Microcontroller Programming » EEPROM confusion
July 27, 2011 by missle3944 |
Hi guys, Im using mjswan's code for eeprom storage in the library. I already read through the avr tutorial and I understand it alittle bit. But I still dont get how to initiallize the eeprom and how to store variables and stuff like that. Anyways heres my code but it wont even let me put it on the MCU b/c of sooo many errors. It says that false is undeclared??? I'm confused!!
|
---|---|
July 28, 2011 by Ralphxyz |
missle3944, you might want to work through this EEPROM Tutorial from Dean Camera over on AVRfreaks.Net. He explains it so well that even I "should" be able to use the 168 EEPROM. Dean has other excellant tutorials also. Ralph |
July 28, 2011 by missle3944 |
Hi ralph, Thanks for the siggestion but I already read through that one too. But I don't get how you initialize the EEPROM and how to write values to it? -missle3944 |
July 28, 2011 by bretm |
Can you post the complete code? That snippet is missing a lot of things such as the #include directives that define the eeprom functions, "false", etc. Once you have it correctly compiling, the way you use it is to call readsavedvars() to load the saved variables. It initializes the EEPROM for you if the variables haven't been saved before. After you change the values in savedvars you call writesavedvars() to update the EEPROM. |
July 28, 2011 by missle3944 |
Heres the code for the HEADER:
For the main c code-
|
July 28, 2011 by missle3944 |
All right Guys, I erased that confusing code and started out with a new slate. Heres my barecode to read from location 46 of the eeprom. The code compiles fine in the compiler. But I dont think it does anything b/c theres nothing to read. Can you guys guide me in the steps of reading and writing to the eeprom possibly? heres my code
Thanks a bunch :D -missle3944 |
July 28, 2011 by Noter |
Here's all the eeprom functions - eeprom_write_byte is used to store a single byte of data in eeprom. http://www.nongnu.org/avr-libc/user-manual/groupavreeprom.html |
July 28, 2011 by missle3944 |
Hi guys, Finally got it to work. But how do I display an 8 bit integer on the lcd? Thanks for the link noter. Now I'm working with floating point numbers in the eeprom. -missle3944 |
July 28, 2011 by Noter |
You could format using printf() or just use the lcd_write_int16 routine in libnerdkit with a typecast to a 16bit integer in the call:
|
July 28, 2011 by missle3944 |
WOW thanks Noter. I dont think i would have found this :D. How can you put a 8 bit int into a 16bit spot? -missle3944 |
July 28, 2011 by Noter |
The (int16_t) in front of the variable name is called a typecast and it temporarily converts from one data type to another. In this case the int8 becomes int16 and then the function is called with the temporary int16. You can find many explainations and examples on the web, just search "typecast c". |
July 28, 2011 by missle3944 |
Hi noter, Reached another wall... For some reason the compiler wants me to put quote "expected ";",";" or ")" unquote. heres my code snippet:
I'm using the site you gave to me on all of the syntax of avr/eeprom.h. There examples are hard to follow becuase Im not sure if I add parenthisis around anything b/c my code for 1 byte into eeprom had quotes around unsigned8bit here:
were as theirs doesnt:
just a question. -missle3944 |
July 29, 2011 by Noter |
A function doesn't need the return type when called, only when defined. Remove the void from the front of the line where you call eeprom_write_float. In the second example the (uint8_t*) is a typecast. It makes the value 46 into a pointer to an int8 for the purpose of the function call. Function definitions are a little different than calls. In the definition you specify the data types expected and returned where in the call you just supply/receive those data types. Your 3rd line is from the function definition although the return type of uint8_t is not present in your example. Here is a good tutorial on c functions as well as the rest of the c language. http://www.crasseux.com/books/ctutorial/Functions.html#Functions |
Please log in to post a reply.
Did you know that hobby servos are controlled through a particular kind of PWM (Pulse Width Modulation) signal? Learn more...
|