Beginning EEPROM

Go To Last Post
8 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I just start to learn about EEPROM and read from many sources. I've some confusion at some point.

    byte and word:what is the main difference among them. I notice from the examples that when a variable is declared for byte it is uint8_t and for word it's uint6_t.Is it kind of byte takes one byte space and word takes 2 byte? can I assign values like normal variables to those variables which I use to write in eeprom?
    block: In this block functions say write or read at last part we give "size_t n". is this the number of bytes we want to read or size of data type we are using like char or int?
    If it's the number of byte we want to read/write then which I use when I want to write a "char arr[10]" string? should it 10*sizeof(char) if char takes 2 byte?

sorry for this long questions and if there is any stupid questions. :shock:
I'm just confused.

Last Edited: Wed. Dec 11, 2013 - 05:21 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

:what is the main difference among them

On an AVR a char (byte) is 8bit and int (word) is 16bit. The names for these types are a better idea as you can always tell from the type name how wide it is. uint8_t and int8_t are the unsigned and signed 8bit wide types (byte) and uint16_t and int16_t are the 16 bit wide types (word). Also the uint32_t and int32_t types are what the avr-gcc EEPROM functions would describe as dword.
Quote:

can I assign values like normal variables to those variables which I use to write in eeprom?

I've assumed you are talking about using avr-gcc (as found in AS6). In that compiler you cannot just define a variable as eeprom type and then assign to it (as you can in some C compilers). In avr-gcc you have to use the eeprom_write*() or eeprom_update*() functions so you would do something like:

uint16_t eeword EEMEM;

eeprom_update_word(&eeword, 12345);

which would write 12345 to that 16 bit location in EEPROM.

Use the eeprom_read/write/update_block() functions for non-standard types that are some length other than 8, 16 or 32 bit.

PS if it is avr-gcc you are using then read this tutorial about using EEPROM:

https://www.avrfreaks.net/index.p...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think I understand about byte and word.
but what about my question about block.
In this link, examples are given as an uint8_t type array which takes only one byte for each element.

#include  

void main(void) 
{ 
    uint8_t StringOfData[10]; 

    eeprom_read_block((void*)&StringOfData, (const void*)12, 10); 
}

what if this is

uint32_t StringOfData[10]; 

do I still write 10 or 10*4 as the number of byte to be read?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

do I still write 10 or 10*4 as the number of byte to be read?

The size of the block is always specified in bytes. So if you are accessing [10] objects that are each 32 bits (4 bytes) wide then it is 40 bytes that need to be read or written.

BTW

(const void*)12

don't do this. Use named addressing. You wouldn't think of making numeric address access to variables in RAM so why do it to the EEPROM?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

uint16_t eeword EEMEM; 


what it mean by writing EEMEM last after variable name?
Should it not be like
uint16_t EEMEM eeword ; 

?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Anklon wrote:

what it mean by writing EEMEM last after variable name?

It makes no difference if it in front or after the variable name, the effect is the same.

Alex

"For every effect there is a root cause. Find and address the root cause rather than try to fix the effect, as there is no end to the latter."
Author Unknown

Last Edited: Wed. Dec 11, 2013 - 06:35 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Look you are going to have to pick one of these two EEPROM threads you have created and we'll continue with that one. I will lock the other one. Which one do you want to continue with.

(and to answer your question "EEMEM" is a variable __attribute__ so it doesn't really where in the definition it occurs).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Mine problem in this part is actually solved.
I just create another post cause in this post I ask about some kind of conceptual fact.
then I have face some problem to implement those and think It might be good to post as new topic cause it's different problems.
thx to all for helping.