Analysis of the difference and usage of EEPROM and FLASH in AVR microcontrollers

Publisher:yanfeng00Latest update time:2020-01-15 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. EEPROM Introduction

Electrically Erasable Programmable Read Only Memory Electrically Erasable Programmable Read Only Memory

Development process: ROM -> PROM -> EPROM -> EEPROM


2. The difference between EEPROM and FLASH

2.1 Differences in usage

FLASH is used to store programs and cannot be changed during program execution. The programs we write are burned into FLASH;

RAM is used as data storage when the program is running;

EEPROM is used to store data that users do not want to lose after power failure, and parameters used when starting the machine. It can be changed during operation.


FLASH is used to store program code. In some cases, it may also be used to save data. Of course, the premise is that the FLASH process of the microcontroller is self-writable (erasable during operation). However, it should be noted that the number of times FLASH can be erased is usually less than 10,000 times, and FLASH can usually only be erased by block. EEPROM cannot be used to store programs. Usually, the instruction addressing of the microcontroller cannot reach this area. The number of times EEPROM can be erased should be millions, and it can be erased by byte. EEPROM can be written arbitrarily within a PAGE, while FLSAH must be erased to BLANK first and then written. Generally, there is no single-byte erase function, and at least one sector must be erased.

Analysis of the difference and usage of EEPROM and FLASH in AVR microcontrollers

2.2 Structural Differences

Both EEPROM and FLASH are non-volatile memories.

The full name of FLASH is FLASH EEPROM, but its operation method is different from that of conventional EEPROM.

The biggest difference between FLASH and EEPROM is that FLASH operates by sector, while EEPROM operates by byte. The two have different addressing methods and different storage unit structures. FLASH has a simpler circuit structure, and the same capacity occupies a smaller chip area, so the cost is naturally lower than that of EEPROM, so it is suitable for use as a program memory, while EEPROM is more used as a non-volatile data memory. Of course, it is also possible to use FLASH as a data memory, but the operation is much more troublesome than EEPROM, so a more "humanized" MCU design will integrate two non-volatile memories, FLASH and EEPROM, while cheap designs often only have FLASH. Early electrically erasable MCUs all have EEPRM structures, which are now basically discontinued.


3. How to use EEPROM

AVRGCC has built-in EEPROM read and write functions.

The header file #include must be included when using it. Some read and write functions are as follows:

#define eeprom_is_ready() bit_is_clear(EECR, EEWE) //Check if EEPROM is ready. OK returns 1 (return EEWE bit)

#define eeprom_busy_wait() do {} while (!eeprom_is_ready()) //wait for EEPROM operation to complete

extern uint8_t eeprom_read_byte (const uint8_t *addr); //Read one byte of 8-bit EEPROM data at the specified address

extern uint16_t eeprom_read_word (const uint16_t *addr); //Read a word of 16-bit EEPROM data at the specified address

extern void eeprom_read_block (void *buf, const void *addr, size_t n); //Read EEPROM data of specified length starting from specified address

extern void eeprom_write_byte (uint8_t *addr, uint8_t val); //Write a byte of 8-bit EEPROM data to the specified address

extern void eeprom_write_word (uint16_t *addr, uint16_t val); //Write a word of 16-bit EEPROM data to the specified address


The configuration command is sent to the MCU through the serial port. After receiving the command, the MCU uses the function write_EEPROM_config() to store the corresponding configuration information in the EEPROM. When the system is initialized, the function read_EEPROM_config() is used to retrieve the corresponding data from the EEPROM for system initialization.

Reference address:Analysis of the difference and usage of EEPROM and FLASH in AVR microcontrollers

Previous article:Serial communication between AVR microcontroller USART and PC
Next article:Analysis of the sensing principle of RC capacitive touch in AVR microcontroller

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号