Operácie

AVR Pamäťové priestory: Rozdiel medzi revíziami

Zo stránky SensorWiki

Balogh (diskusia | príspevky)
Nová stránka: == EEPROM == How to access AVR microcontroller EEPROM (Electronically Erasable Read-Only memory) memory in C? This type of memory allows developers to store constants, parameters...
 
Balogh (diskusia | príspevky)
Bez shrnutí editace
Riadok 1: Riadok 1:
The memory space “seen” by AVRGCC runs from addresses:
0×00000000 up to 0×0007FFFF for Flash memory,
0×00800000 up to 0×0080FFFF for RAM, and
0×00810000 up to 0×0081FFFF for EEPROM.
This means if you need your variable to be stored at specific
RAM address you need to add offset 0×00800000 to your desired
RAM address like if you want the .data section to start at 0×1100,
pass 0×801100 at the address to the linker.
Same is with EEPROM just offset is 0×00810000. For flash memory
you don’t need to add offsets.


== EEPROM ==
== EEPROM ==

Verzia z 19:38, 6. november 2008

The memory space “seen” by AVRGCC runs from addresses:

0×00000000 up to 0×0007FFFF for Flash memory,
0×00800000 up to 0×0080FFFF for RAM, and
0×00810000 up to 0×0081FFFF for EEPROM.

This means if you need your variable to be stored at specific RAM address you need to add offset 0×00800000 to your desired RAM address like if you want the .data section to start at 0×1100, pass 0×801100 at the address to the linker.

Same is with EEPROM just offset is 0×00810000. For flash memory you don’t need to add offsets.


EEPROM

How to access AVR microcontroller EEPROM (Electronically Erasable Read-Only memory) memory in C?

This type of memory allows developers to store constants, parameters, values and are stored also after the power loss.

To use this memory area just include eeprom.h header library from avr directory

#include "avr/eeprom.h"

Variable declaration (use an attribute EEMEM):

 #include "avr/io.h"
 #include "avr/eeprom.h"

  uint8_t EEMEM eeprombyte=0x10;              // Store a byte
 uint16_t EEMEM eepromword=0x5555;            // Store a word
  uint8_t EEMEM eepromstring[5]={"Test\0"};   // Store a string

int main(void)
{
  uint8_t RAMbyte;                            //Standard variable in RAM (byte)
 uint16_t RAMword;                            //Standard variable in RAM (word)
  uint8_t RAMstring[5];

//read byte from EEPROm and store to RAM

 RAMbyte = eeprom_read_byte(&eeprombyte);
 RAMword = eeprom_read_word(&eepromword);
 eeprom_read_block ((void *)&RAMstring, (const void *)&eepromstring,5);

return (0);
}

Don't forget that compiler creates separate .eep file which has to be written to chip separately!