Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

What is the use of EEPROM in a Microcontroller

Status
Not open for further replies.

Sashvat

Member
Hi guys, I have a doubt on what is the use of EEPROM in a Microcontroller, I have no understanding what so ever about this, I understand flash is used to hold the program we write, SRAM is where the code is loaded onto and the CPU starts executing it from the SRAM. but I don't get, what's the use of EEPROM in a Microcontroller? Thanks
 
Its basically where data that may or may not be constantly changing can be stored. It allows the writing/erasing of individual bytes where flash typically requires larger sections of data to be erased and written. I think the eeprom sections have longer life as well when considering how many times it can be written.

Think of something like your odometer cluster. The main flash memory stores the over all function of the cluster that never changes, where the eeprom would store things like your maintenance reminders, configurable user options and mileage that is constantly changing,
 
Last edited:
A processor should have I (instruction) and D (Data) space. A program should not write self-modifying code. The program couteris kept out of D-space by design.

larger CPU's also have user and Kernal I and D space so the operating system cannot inadvertently execute a user's code and the user cannot access devices. A user program cannot control a disk drive.

You can execute a program from EE-Prom and have a small data space for variables.

A laptop has a BIOS which might be EE-prom. This changes stuff that the bootloader needs like the order of the boot devices to try. the hard drive usually has the program which is loaded into RAM and executed. It does not have to be that way.
 
We use it for such as configuration information.

Things a user can change or configure after purchase, that should then be stored indefinitely unless the user wants to change the settings again.

It can also be used to store calibration data, values determined during initial testing or ongoing self-adjustment values like zero offsets and gain tuning.

Anything that needs values storing or changing outside of the program itself, where they are permanent and not lost when power is off.

Some MCUs allow the program flash to be written from the program, and some people use that to store calibration or temporary data - but flash has a limited life in comparison to EEPROM and there have been threads on here about programs using flash to store variable data stopping working properly as the flash memory cells fail.

It's OK for one-off calibration values or things that change very rarely, but not for any regularly changing data that needs to be retained.


Edit:
Reading the question again, you have a misconception.

In a microcontroller, the program is executed directly from FLASH memory. RAM is also often extremely limited in smaller ones.

In general, RAM is only used for data; program variables. MCUs often cannot execute anything in RAM [data] address space anyway.
 
Last edited:
Its basically where data that may or may not be constantly changing can be stored. It allows the writing/erasing of individual bytes where flash typically requires larger sections of data to be erased and written. I think the eeprom sections have longer life as well when considering how many times it can be written.

Think of something like your odometer cluster. The main flash memory stores the over all function of the cluster that never changes, where the eeprom would store things like your maintenance reminders, configurable user options and mileage that is constantly changing,
so for example to blink an LED in a Microcontroller, when I set " int LEDpin = 13; " does it store the value of 13 in the EEPROM?
 
does it store the value of 13 in the EEPROM?
most likely not.
The " int LEDpin = 13; " that your typed is turned into instructions that are stored in FLASH or ROM or what ever the instructions are stored in. The "13" is part of the instructions.
You can type "" int LEDpin = [pin_name]; " where some where you defined pin_name=13. Same results.
You could type " int LEDpin = ; [pin_name]" Where you defined pin-name is at RAM location 100. And RAM location 100 has been set to 13 (load 13 into RAM100) Now the instructions will be different but the final results will be the same. At this point you can change RAM 100 to be 14 and get the output on a different pin at any time.
You can define pin_name to a EEPROM location. The code will look in EEPROM (address) to find what pin to use. Most likely the EEPROM will be loaded with numbers at compile and these will not be changed often. If you make 1000 computers with the same code but you want 50 to work with pin 13 and the other 50 to work with pin 14 you only need to reprogram one EEPROM location to change which pin to use.
Another example of EEPROM. My TV forgets most things when the power is removed. But it remembers what channel I was watching, what volume, what brightness, etc. That is stored in EEPROM when I make changes. And retrieved when I turn on the TV. (start up on channel 10 is not stored in code but in EEPROM)

All things depend on what type of computer! Most often the ROM or FLASH contains code and some data that can not be changed like "pin=13". No computers can change their ROM and likely can not change the FLASH. RAM is temporary data. EEPROM is data that is remembered during loss of power. You can read RAM and EEPROM exactly the same. Writing EEPROM take a long time. (very slow)
 
most likely not.
The " int LEDpin = 13; " that your typed is turned into instructions that are stored in FLASH or ROM or what ever the instructions are stored in. The "13" is part of the instructions.
You can type "" int LEDpin = [pin_name]; " where some where you defined pin_name=13. Same results.
You could type " int LEDpin = ; [pin_name]" Where you defined pin-name is at RAM location 100. And RAM location 100 has been set to 13 (load 13 into RAM100) Now the instructions will be different but the final results will be the same. At this point you can change RAM 100 to be 14 and get the output on a different pin at any time.
You can define pin_name to a EEPROM location. The code will look in EEPROM (address) to find what pin to use. Most likely the EEPROM will be loaded with numbers at compile and these will not be changed often. If you make 1000 computers with the same code but you want 50 to work with pin 13 and the other 50 to work with pin 14 you only need to reprogram one EEPROM location to change which pin to use.
Another example of EEPROM. My TV forgets most things when the power is removed. But it remembers what channel I was watching, what volume, what brightness, etc. That is stored in EEPROM when I make changes. And retrieved when I turn on the TV. (start up on channel 10 is not stored in code but in EEPROM)

All things depend on what type of computer! Most often the ROM or FLASH contains code and some data that can not be changed like "pin=13". No computers can change their ROM and likely can not change the FLASH. RAM is temporary data. EEPROM is data that is remembered during loss of power. You can read RAM and EEPROM exactly the same. Writing EEPROM take a long time. (very slow)
can you give some kind of an analogy for this please?
 
What controller type and IDE You want to use?
The EEPROM access differs by the used controller and the IDE.
 
can you give some kind of an analogy for this please?

Imagine you buy an electronic timeswitch, or central heating programmer.
When you set it up, the times to switch on & off each day could be stored in EEPROM.

That means it there is a power failure, you do not have to re-enter all the times again, there are saved unto you explicitly enter new settings.

That's just an example, but the generic type of thing it may be used for - it's information that is not part of the actual program, and it's that does not want to be kept in RAM and lost if power fails.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top