I am writing one AVR Mikrobasic Program which my Atmega32 flash memory is fulled.

Can I use EEPROM space for saving my functions routines instead of flash memory for releasing some space of flash memory?

  • 2
    \$\begingroup\$ no. EEPROM is for data only. if you have data tables in flash, they could be moved to EEPROM (if mikrobasic supports this), but AVR can't execute code in EEPROM. \$\endgroup\$ – Jasen Dec 29 '16 at 7:13
  • 2
    \$\begingroup\$ The AVR controllers have about 10 to 100 times more program flash memory than they have EEPROM memory. The only reasons to use the EEPROM at all is the higher number of erase cycles it has and that it can be erased at byte granularity. (Plus, some ATtiny controllers can't change the program flash from within the running program, or you don't want that to be enabled.) \$\endgroup\$ – Janka Dec 29 '16 at 8:12


From the Atmega328PB datasheet:

In order to maximize performance and parallelism, the AVR uses a Harvard architecture – with separate memories and buses for program and data. Instructions in the program memory are executed with a single level pipelining. While one instruction is being executed, the next instruction is pre-fetched from the program memory. This concept enables instructions to be executed in every clock cycle. The program memory is In-System Reprogrammable Flash memory.

(Emphasis mine.)

Harvard architecture means, that instruction and data processing is separated within the CPU. From Wikipedia:

The Harvard architecture is a computer architecture with physically separate storage and signal pathways for instructions and data.

Another quote from the Atmel328P datasheet, section 11.1:

This section describes the different memory types in the device. The AVR architecture has two main memory spaces, the Data Memory and the Program Memory space. All memory spaces are linear and regular.

Take a look at this block diagram found in the Atmel328PB datasheet:

AVR architecture block diragram from the Atmel 328PB datasheet

As you can see the flash memory and the instruction pipeline and the EEPROM are physically separated.

Aside: while running a program from memories other than flash is not possible, loading data from program memory is possible using the LPM instruction found on some AVR platforms.

Reference from the datasheet:

Constant tables can be allocated within the entire program memory address space, using the Load Program Memory (LPM) instruction.

| improve this answer | |
  • 1
    \$\begingroup\$ Where is the EEPROM in this Diagram? \$\endgroup\$ – MaNyYaCk Dec 29 '16 at 10:23
  • 1
    \$\begingroup\$ Well it's not shown because it's not related to instruction loading. The diagram is only revolves around the ALU. You may take a look at figure 7-1 (pg.) of an older Atmega328P datasheet. It shows the EEPROM connected to the databus but not to the instruction register (which holds the loaded instruction). \$\endgroup\$ – try-catch-finally Dec 29 '16 at 11:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.