Operácie

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

Z SensorWiki

Riadok 53: Riadok 53:
  
 
Don't forget that compiler creates separate .eep file which has to be written to chip separately!
 
Don't forget that compiler creates separate .eep file which has to be written to chip separately!
 +
 +
 +
 +
==== Flash ====
 +
 +
Example of table, located in flash:
 +
 +
<source lang="C">
 +
#include
 +
uint8_t sinetable[] PROGMEM = { … };
 +
 +
level = pgm_read_byte_near(sinetable + phase);
 +
 +
</source>

Verzia zo dňa a času 19:40, 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!


Flash

Example of table, located in flash:

#include
uint8_t sinetable[] PROGMEM = { … };

level = pgm_read_byte_near(sinetable + phase);