What is a memory chip and how to program microcircuits. Main Features of EEPROM Memory Why AVR

Lesson 15

Part 1

Internal non-volatile EEPROM memory

I think, maybe not everyone, but many people know that in AVR controllers, in addition to the main RAM, as well as memory for storing firmware, there is also non-volatile memory like EEPROM. This memory is made using the technology of electrical erasure of information, which, unlike its predecessor EPROM, in which erasure was carried out only using ultraviolet rays, made it possible to use this type of memory almost everywhere. As we know, there is also non-volatile memory such as Flesh, which is much cheaper, but which also has a significant disadvantage. There it is impossible to erase a single byte; erasing is performed only in blocks, which is not entirely convenient in some cases, especially when little information needs to be stored, and this information represents small setting parameters. Therefore, we should also focus on this type of memory. And not only because it is present in the controller, but because it is very convenient for storing some quantities that we will need even after the controller has lost power.

Since we are working with the Atmega8A controller, we will open the technical documentation of this MK and see there that we have a total of 512 bytes of such memory. However, this is not so little. If, for example, we program some kind of alarm clock so that the settings data is not lost after the power is turned off, we can easily refer to this memory. The documentation also says that this memory is guaranteed to survive 100,000 write/read cycles.

Now this begs the question. How is the process of working with this memory organized in a microcontroller? AVR? As always, Atmel took care of this and organized this process at the hardware level, which is very pleasing because we constantly have to save controller resources. To control this hardware level, there are certain registers.

One of them is a register pair EEAR. Why a couple, but because 512 addresses will not fit into 8 bits, one more is required

We will see exactly how we will address during the programming process EEPROM.

Next is the data register EADR

We will write data to this register in order to write it to a specific EEPROM memory address, as well as to read it from a specific address of the same memory.

Well, as usual, almost no peripheral or technology organized at the hardware level can do without a control register. Our managing register is the register EECR

Let's immediately get to know the bits of this register.

Bit EERE— a bit that causes the process of reading from EEPROM memory to begin. And, as soon as the data has been read and written to the data register, this bit will be reset. Therefore, we can consider this bit not only a control bit, but also a status or status bit.

Bit EEWE— a bit, the setting of which commands the controller to write data from the data register to a specific EEPROM address. After the writing procedure is completed, this bit is also reset independently.

Bit EEMWE— a bit that allows (not starts) the recording process.

Bit EERIE— bit that enables interrupts.

Well, now let's move on to the project. The project was created in the usual standard way and named Test13. The file was also included main.h and files are created eeprom.h And eeprom.c.

Here is the source code of the created files

Test13.c:

#include"main.h"

intmain( void)

{

while(1)

{

}

}

#ifndefMAIN_H_

#defineMAIN_H_

#defineF_CPU8000000UL

#include

#include

#include

#include

#include

#include"eeprom.h"

 

#endif/* MAIN_H_ */

eeprom.h

#ifndefEEPROM_H_

#defineEEPROM_H_

#include"main.h"

voidEEPROM_write( unsignedintuiAddress, unsignedcharucData);

unsignedcharEEPROM_read( unsignedintuiAddress);

#endif/* EEPROM_H_ */

eeprom.c

#include"eeprom.h"

First, accordingly, we will try to write data to the EEPROM memory. Well, it’s logical, since while we haven’t written anything down, we also have nothing to read.

Well, let's not bother ourselves and insert the code for the write function, as well as the read function from the example in the technical documentation, into the file eeprom.c and remove the English-language comments, inserting Russian-language ones there. After all the corrections the file will look like this

#include"eeprom.h"

voidEEPROM_write( unsignedintuiAddress, unsignedcharucData)

{

while( EECR& (1<< EEWE))

{}

EEAR= uiAddress; //Set the address

EEDR= ucData; //We feed data into the register

EECR|= (1<< EEMWE); //Allow recording

EECR|= (1<< EEWE); //Write a byte into memory

}

unsignedcharEEPROM_read( unsignedintuiAddress)

{

while( EECR& (1<< EEWE))

{} //wait for the end flag to be released by the last memory operation

EEAR= uiAddress; //Set the address

EECR|= (1<< EERE); //Start a read operation from memory to the data register

returnEEDR; //Return the result

}

Let's write prototypes for these functions in a file eeprom.h

#include"main.h"

voidEEPROM_write( unsignedintuiAddress, unsignedcharucData);

unsignedcharEEPROM_read( unsignedintuiAddress);

Now let’s call the write function in the main() function and thereby try to write some 8-bit value to address 1. In general, addressing in this memory starts from 0

intmain( void)

EEPROM_write(1, 120);

While(1)

We use the same debug board for experiments, without connecting anything to it at all

Let's assemble the project and go to the firmware program Avrdude.

Let's select our firmware file there, then try to read the controller, then erase everything using the "erase all" button

Also in the avrdude program there is another line "Eeprom". We can use this line to write to this memory not programmatically, but from a file. But we will write from our program, and we will use this line to read EEPROM memory into a file. You can write the path in this line by hand and the file will be created by itself. Let's write, for example, "C:\1\11111" and click "Read", and along this path all information from the EEPROM memory will be written to the specified file

You can write any path, as long as the media with that letter indicated on the left exists and is writable. It is also better to create the folder in advance.

Let’s now find this file on the disk and open it in Notepad

This file has approximately the same format as the firmware file. First the address, then 32 bytes of information and then a checksum for these 32 bytes. If we have never written anything to the EEPROM memory, then we will have FFs at all addresses, that is, we have ones in all memory bits.

We close the file, try to flash the controller, then again read the EEPROM memory into the file and open the file

We see that the number "78" was written to the file, which means 120 in decimal format.

Now let's try to press the "Erase everything" button, in this case the EEPROM memory should not be erased.

We read the EEPROM into the file again, open the file and see that the memory has been erased, we again have “FF” everywhere.

Why did it happen? Because you need to adjust the fuses. Reading fuses

Let's pay attention to the EESAVE bit. When this bit is one (as we have, the bits are inverted), then we force the EEPROM memory to be erased when the power is turned off, as well as when erased. And to prevent this from happening, this bit needs to be reset, that is, put a checkmark in it and flash the fuses.

We flash the fuses, erase the controller, flash the controller, erase it again, read the EEPROM memory into a file and open it. Now we see that nothing has been erased from us

Now let's try to disconnect the controller from the power supply and apply power again after a while. Again we read the EEPROM into the file, everything is intact. Great!

In the next part of the tutorial we will try to programmatically read data from EEPROM memory.

Watch VIDEO TUTORIAL (click on the picture)

Post Views: 7,259

  • Tutorial

Summary: If you periodically update some value in the EEPROM every few minutes (or a few seconds), you may encounter a problem with the EEPROM cells wearing out. To avoid this, it is necessary to reduce the frequency of entries into the cell. For some types of EEPROM, even writing more frequently than once per hour can be a problem.

Time flies when you're recording data

EEPROM is commonly used to store configuration parameters and operating logs in embedded systems. For example, you may want a black box function to record the latest data at the time of an accident or power loss. I've seen specifications requiring data like this to be recorded every few seconds.

But the problem is that EEPROM has a limited number of entries. After 100,000 or a million writes (depending on the specific chip), some of your systems will begin to experience problems with EEPROM failure. (Look at the datasheet for a specific figure. If you want to release a large number of devices, "worst case" is probably more important than "typical"). A million records seems like a lot, but in reality it will end very quickly. Let's look at an example, assuming we need to store a measured voltage of one cell every 15 seconds.

1,000,000 records with one record every 15 seconds gives records per minute:
1,000,000 / (4 * 60 minutes/hour * 24 hours/day) = 173.6 days.
In other words, your EEPROM will exhaust its reserve of a million entries in less than 6 months.

Below is a graph showing the time to wear out (in years) based on the refresh period of a specific EEPROM cell. The cutoff line for a product with a 10-year lifespan is one update every 5 minutes 15 seconds for a chip with a 1 million write lifespan. For EEPROM with a resource of 100K, you can update a specific cell no more than once every 52 minutes. This means you shouldn't expect to update a cell every few seconds if you want your product to last for years rather than months. The above scales linearly, however, in this device there are also secondary factors such as temperature and access mode.

Reduce frequency

The most painless way to solve the problem is to simply write data less often. In some cases, system requirements allow this. Or you can only record when there are any big changes. However, with an event-based entry, be aware of the possible scenario where the value will fluctuate continuously, causing a stream of events that will wear out the EEPROM.
(It would be nice if you could determine how many times the EEPROM was written to. But this would require a counter to be stored in the EEPROM... which makes the problem a wear-out problem.)

Low Power Interrupt

Some processors have a low power interrupt that can be used to write one last value to the EEPROM while the system shuts down due to power loss. In general, you store the value of interest in RAM, and save it to EEPROM only when the power is turned off. Or perhaps you write the EEPROM from time to time, and write another copy to the EEPROM as part of the shutdown procedure to ensure that the most recent data is written.
It is important to make sure that there is a large power supply capacitor that will maintain enough voltage to program the EEPROM for a long enough time. This may work if you need to write one or two values, but not a large block of data. Be careful, there is a lot of room for error here!

Ring buffer

The classic solution to the wearout problem is to use a FIFO ring buffer containing the N most recent value entries. You will also need to store a pointer to the end of the buffer in EEPROM. This reduces EEPROM wear by an amount proportional to the number of copies in that buffer. For example, if a buffer passes through 10 different addresses to store one value, each specific cell is modified 10 times less often, and the write resource increases 10 times. You will also need a separate counter or timestamp for each of the 10 copies so that you can determine which one was the last one at the time of shutdown. In other words, you will need two buffers, one for the value and one for the counter. (Storing the counter at the same address will cause it to wear out, since it must be incremented with each write cycle.) The disadvantage of this method is that it takes 10 times more space to get 10 times more life expectancy. You can be smart and pack the counter along with the data. If you're writing a lot of data, adding a few bytes for the counter isn't that big of a deal. But in any case, you will need a lot of EEPROM.
Atmel has prepared an application note containing all the gory details:
AVR-101: High Endurance EEPROM Storage: www.atmel.com/images/doc2526.pdf

Special case for record counter

Sometimes you need to save the counter, and not the values ​​themselves. For example, you may want to know the number of times the device is turned on, or the operating time of your device. The worst thing about counters is that they constantly change the least significant bit, wearing out the low-order EEPROM cells faster. But even here it is possible to apply some tricks. Microchip's application note has some clever ideas, such as using Gray code to ensure that only one bit of a multi-byte counter changes when the counter value changes. They also recommend using correction codes to compensate for wear. (I don’t know how effective the use of such codes will be, since it will depend on how independent the bit errors will be in the counter bytes, use at your own peril and risk, author’s note). See the app note: ww1.microchip.com/downloads/en/AppNotes/01449A.pdf

Note: For those who would like to know more, Microchip has prepared a document containing detailed information about the design of EEPROM cells and their wear with diagrams:
ftp.microchip.com/tools/memory/total50/tutorial.html

Let me know if you have any interesting ideas for combating EEPROM wear.

Source: Phil Koopman, “Better Embedded System SW”
betterembsw.blogspot.ru/2015/07/avoiding-eeprom-wearout.html

Translator's note: in recent years, EEPROM chips have appeared with a page erase organization (similar to FLASH chips), where it is logically possible to address cells (read, write and erase) byte by byte, but at the same time the chip, invisible to the user, erases the entire page and overwrites it with new data. Those. By erasing cells at address 0, we actually erased and overwrote cells with addresses 0...255 (with a page size of 256 bytes), so the buffer trick will not help in this case. When the record resource of such a microcircuit is exhausted, not just one cell, but the entire page fails. In the datasheets for such microcircuits, the recording resource is indicated for the page, not for a specific cell. See, for example, the datasheet for 25LC1024 from Microchip.

Tags: Add tags

Microcircuits for various purposes are used as part of modern electronics. A huge variety of such components is complemented by memory chips. This type of radio components (among electronics engineers and the people) is often simply called chips. The main purpose of memory chips is to store certain information with the ability to enter (write), change (overwrite) or completely delete (erase) by software. The general interest in memory chips is understandable. For masters who know how to program memory chips, wide opportunities open up in the field of repair and configuration of modern electronic devices.

A memory chip is an electronic component, the internal structure of which is capable of storing (remembering) entered programs, any data, or both at the same time.

Essentially, the information loaded into the chip is a series of commands consisting of a set of microprocessor computing units.

It should be noted: memory chips are always an integral addition to microprocessors - control chips. In turn, the microprocessor is the basis of the electronics of any modern technology.

A set of electronic components on the board of a modern electronic device. Somewhere among this mass of radio components there is a component capable of storing information.

Thus, the microprocessor controls, and the memory chip stores the information needed by the microprocessor.

Programs or data are stored on a memory chip as a series of numbers - zeros and ones (bits). One bit can be represented by a logical zero (0) or a logical one (1).

In a single form, bit processing seems complex. Therefore, the bits are combined into groups. Sixteen bits make up a group of “words”, eight bits make up a byte - a “part of a word”, four bits - a “piece of a word”.

The most commonly used software term for chips is byte. This is a set of eight bits that can take from 2 to 8 numeric variations, giving a total of 256 different values.

To represent a byte, a hexadecimal number system is used, which provides for the use of 16 values ​​from two groups:

  1. Digital (from 0 to 9).
  2. Symbolic (from A to F).

Therefore, combinations of two hexadecimal characters also contain 256 values ​​(from 00h to FFh). The trailing "h" character indicates hexadecimal numbers.

Organization of memory chips

For 8-bit memory chips (the most common type), the bits are combined into bytes (8 bits) and stored at a specific "address".

The assigned address allows access to bytes. The eight access address bits are output through eight data ports.


Organizing the structure of a storage device. At first glance, the algorithm is complex and incomprehensible. But if you want to understand, understanding comes quickly

Electrically erasable programmable read-only memory (EEPROM) chips are metal oxide semiconductor computer chips that are used on a printed circuit board. This type of chip can be erased and reprogrammed using a strong electronic signal. Because this can be done without removing the chip from the device it is connected to, EEPROM chips are used in many industries.
The EEPROM chip contains non-volatile memory, so its data is not lost if the power supply to the chip is interrupted. This type of chip can be selectively programmed, meaning that part of its memory can be changed with a new overwrite without affecting the rest of the memory. The information stored inside an EEPROM chip is permanent until it is erased or reprogrammed, making it a valuable component in computers and other electronic devices.

EEPROM chips are based on floating gate transistors. The EEPROM chip is programmed by forcing programmable information in the form of electrons through the gate oxide. The floating gate then provides storage for these electrons. A memory cell is considered programmed when it is charged with electrons, and this is represented by a zero. If a memory cell is not charged, it is not programmed and is represented by a one.

A wide range of devices require memory, so EEPROM chips have many applications in the consumer electronics field. They are used in gaming systems, televisions and computer monitors. Hearing aids, digital cameras, Bluetooth technology and gaming systems also use EEPROM chips. They are used in the telecommunications, medical and manufacturing industries. Personal and business computers contain EEPROM.

The EEPROM chip also has a wide range of applications in the automotive industry. It is used in anti-lock braking systems, air bags, electronic stability controls, transmissions and engine control units. EEPROM chips are also used in air conditioning units, instrument panel displays, body control modules, and keyless entry systems. These chips help monitor fuel consumption and are also used in various diagnostic systems.

There is a limit to the number of repetitions that can be overwritten by the EEPROM chip. The layer inside the chip is gradually damaged by numerous rewrites. This is not a big problem because some EEPROM chips can be modified up to a million times. Further advances in technology will likely have a positive impact on what memory chips can do in the future.

Arduino is a whole family of different devices for creating electronic projects. Microcontrollers are very convenient to use and are easy to learn even for a beginner. Each microcontroller consists of a board, programs for operation, and memory. This article will look at the non-volatile memory used in Arduino.

Description of EEPROM memory

Arduino provides its users with three types of built-in device memory: stationary RAM (random access memory or SRAM - static random access memory) - necessary for recording and storing data during use; flash cards – for saving already recorded patterns; – for storage and subsequent use of data.

All data on RAM is erased as soon as the device is rebooted or the power is turned off. The second two save all information before overwriting and allow you to retrieve it if necessary. Flash drives are quite common nowadays. It is worth considering EEPROM memory in more detail.

The abbreviation stands for Electrically Erasable Programmable Read-Only Memory and translated into Russian literally means electrically erasable programmable read-only memory. The manufacturer guarantees the safety of information for several decades after the last power outage (usually a period of 20 years is given, depending on the rate at which the device’s charge decreases).

However, you need to know that the ability to rewrite to a device is limited and is no more than 100,000 times. Therefore, it is recommended to be careful and attentive to the data entered and not to overwrite it again.

The amount of memory, in comparison with modern media, is very small and varies for different microcontrollers. For example, for:

  • ATmega328 – 1kB
  • ATmega168 and ATmega8 – 512 bytes,
  • and ATmega1280 – 4 kB.

It’s designed this way because each microcontroller is designed for a specific volume of tasks, has a different number of pins for connection, and accordingly, a different amount of memory is required. Moreover, this amount is sufficient for commonly created projects.

Writing to EEPROM requires a significant amount of time - approx. 3 ms. If the power is turned off while recording, the data will not be saved at all or may be recorded incorrectly. It is always necessary to additionally check the entered information to avoid failures during operation. Reading data is much faster, and the memory resource is not reduced.

Library

Working with EEPROM memory is carried out using a library that was specially created for Arduino. The main ones are the ability to write and read data. activated by command #include EEPROM.h.

  • For records– EEPROM.write(address, data);
  • For reading– EEPROM.read(address).

In these sketches: address – an argument with the data of the cell where the data of the second argument data is entered; when reading, one argument is used, address, which indicates where the information should be read from.

Function Purpose
read(address) reads 1 byte from EEPROM; address – address from which data is read (cell starting from 0);
write(address, value) writes value (1 byte, number from 0 to 255) to memory at address;
update(address, value) replaces value at address if its old contents are different from the new ones;
get(address, data) reads data of the specified type from memory at address;
put(address, data) writes data of the specified type into memory at address;
EEPROM allows you to use the "EEPROM" identifier as an array to write data to and read from memory.

Writing Integers

Writing integers to non-volatile EEPROM memory is quite simple. Entering numbers occurs when the function is launched EEPROM.write(). The required data is indicated in brackets. In this case, numbers from 0 to 255 and numbers over 255 are written differently. The first ones are entered simply - their volume takes 1 byte, that is, one cell. To write the latter, you must use the operators highByte() for the highest byte and lowByte() for the lowest byte.

The number is divided into bytes and written separately in cells. For example, the number 789 will be written in two cells: the first will contain the factor 3, and the second will contain the missing value. The result is the required value:

3 * 256 + 21 = 789

For « "reunion" of a large integer, the word() function is used: int val = word(hi, low). You need to read that the maximum integer for recording is 65536 (that is, 2 to the power of 16). In cells that have not yet had other entries, the monitor will display the numbers 255 in each.

Writing floating point numbers and strings

Floating point and string numbers are a form of writing real numbers where they are represented by a mantissa and an exponent. Such numbers are written to non-volatile EEPROM memory by activating the function EEPROM.put(), reading, respectively, – EEPROM.get().

When programming, floating point numeric values ​​are designated as float; it is worth noting that this is not a command, but a number. Char type (character type) – used to represent strings. The process of writing numbers on the monitor is started using setup(), reading - using loop().

During the process, the values ​​ovf, which means “overflowing,” and nan, which means “missing a numeric value,” may appear on the monitor screen. This means that the information written to the cell cannot be reproduced as a floating point number. This situation will not arise if you know reliably in which cell what type of information is recorded.

Examples of projects and sketches

Example No. 1

The sketch will write up to 16 characters from the serial port and output 16 characters from the EEPROM in a loop. Thanks to this, data is written to EEPROM and the contents of non-volatile memory are monitored.

// check the operation of EEPROM #include int i, d; void setup() ( Serial.begin(9600); // initialize the port, speed 9600 ) void loop() ( // read EEPROM and output 16 data to the serial port Serial.println(); Serial.print("EEPROM= " ); i= 0; while(i< 16) { Serial.print((char)EEPROM.read(i)); i++; } // проверка есть ли данные для записи if (Serial.available() != 0) { delay(50); // ожидание окончания приема данных // запись в EEPROM i= 0; while(i < 20) { d= Serial.read(); if (d == -1) d= " "; // если символы закончились, заполнение пробелами EEPROM.write(i, (byte)d); // запись EEPROM i++; } } delay(500); }

Example No. 2

For a better understanding, we can create a small sketch that will help in understanding how to work with non-volatile memory. We count all the cells of this memory. If the cell is not empty - output to the serial port. Then fill the cells with spaces. Then we enter the text through the serial port monitor. We write it to EEPROM, and read it the next time it is turned on.

#include int address = 0; // eeprom address int read_value = 0; // data read from eeprom char serial_in_data; // serial port data int led = 6; // line 6 for LED int i; void setup() ( pinMode(led, OUTPUT); // line 6 is configured as output Serial.begin(9600); // baud rate on serial port 9600 Serial.println(); Serial.println("PREVIOUS TEXT IN EEPROM: -"); for(address = 0; address< 1024; address ++) // считываем всю память EEPROM { read_value = EEPROM.read(address); Serial.write(read_value); } Serial.println(); Serial.println("WRITE THE NEW TEXT: "); for(address = 0; address < 1024; address ++) // заполняем всю память EEPROM пробелами EEPROM.write(address, " "); for(address = 0; address < 1024;) // записываем пришедшие с последовательного порта данные в память EEPROM { if(Serial.available()) { serial_in_data = Serial.read(); Serial.write(serial_in_data); EEPROM.write(address, serial_in_data); address ++; digitalWrite(led, HIGH); delay(100); digitalWrite(led, LOW); } } } void loop() { //---- мигаем светодиодом каждую секунду -----// digitalWrite(led, HIGH); delay(1000); digitalWrite(led, LOW); delay(1000); }

Example No. 3

Writes two integers to memory, reads them from EEPROM and outputs them to the serial port. Numbers from 0 to 255 occupy 1 byte of memory, using the function EEPROM.write() are written to the desired cell. For numbers greater than 255, they must be divided into bytes using highByte() And lowByte() and write each byte into its own cell. The maximum number in this case is 65536 (or 2 16).

#include // connect the EEPROM library void setup() ( int smallNum = 123; // integer from 0 to 255 EEPROM.write(0, smallNum); // write a number to cell 0 int bigNum = 789; // split the number > 255 by 2 bytes (max. 65536) byte hi = highByte(bigNum); // high byte byte low = lowByte(bigNum); // low byte EEPROM.write(1, hi); // write high byte of EEPROM to cell 1 .write(2, low); // write the low byte to cell 2 Serial.begin(9600); // initialize the serial port ) void loop() ( for (int addr=0; addr<1024; addr++) { // для всех ячеек памяти (для Arduino UNO 1024) byte val = EEPROM.read(addr); // считываем 1 байт по адресу ячейки Serial.print(addr); // выводим адрес в послед. порт Serial.print("\t"); // табуляция Serial.println(val); // выводим значение в послед. порт } delay(60000); // задержка 1 мин }

Example No. 4

Writing floating point numbers and strings - method EEPROM.put(). Reading – EEPROM.get().

#include // connect the library void setup() ( int addr = 0; // address float f = 3.1415926f; // floating point number (float type) EEPROM.put(addr, f); // write the number f to address addr addr += sizeof(float); // calculate the next free memory cell char name = "Hello, SolTau.ru!"; // create an array of characters EEPROM.put(addr, name); // write the array to EEPROM Serial.begin (9600); // initializing the serial port) void loop() ( for (int addr=0; addr<1024; addr++) { // для всех ячеек памяти (1024Б=1кБ) Serial.print(addr); // выводим адрес в послед. порт Serial.print("\t"); // табуляция float f; // переменная для хранения значений типа float EEPROM.get(addr, f); // получаем значение типа float по адресу addr Serial.print(f, 5); // выводим с точностью 5 знаков после запятой Serial.print("\t"); // табуляция char c; // переменная для хранения массива из 20 символов EEPROM.get(addr, c); // считываем массив символов по адресу addr Serial.println(c); // выводим массив в порт } delay(60000); // ждём 1 минуту }

Example No. 5

Using EEPROM as an array.

#include void setup() ( EEPROM = 11; // write the 1st cell EEPROM = 121; // write the 2nd cell EEPROM = 141; // write the 3rd cell EEPROM = 236; // write the 4th cell Serial .begin(9600); void loop() ( for (int addr=0; addr<1024; addr++) { Serial.print(addr); Serial.print("\t"); int n = EEPROM; // считываем ячейку по адресу addr Serial.println(n); // выводим в порт } delay(60000); }

Working with EEPROM

As mentioned earlier, EEPROM memory is limited. To extend the service life of non-volatile memory, instead of the write() function, it is better to use the update function. In this case, rewriting is carried out only for those cells where the value differs from the newly written one.

Another useful function of the microcontroller memory in question is the ability to use byte storage cells as parts of an integral EEPROM array. In any format of use, it is necessary to constantly monitor the integrity of the recorded data.

Such memory on Arduino standardly stores the most important things for the operation of the controller and device. For example, if a temperature controller is created on such a basis and the initial data turns out to be erroneous, the device will operate “inadequately” to the existing conditions - it will greatly underestimate or overestimate the temperature.

There are several situations where the EEPROM contains incorrect data:

  1. Upon initial activation, there were no entries yet.
  2. During an uncontrolled power outage, some or all of the data will not be recorded or will be recorded incorrectly.
  3. After completion of possible data rewrite cycles.

To avoid unpleasant consequences, the device can be programmed for several action options: apply emergency code data, turn off the system completely, signal a malfunction, use a previously created copy, or others.

To control the integrity of information, a system control code is used. It is created based on the original data record and, when checked, it recalculates the data. If the result is different, it is an error. The most common version of such a check is a checksum - a simple mathematical operation is performed to add all cell values.

Experienced programmers add an additional "exclusive OR" to this code, such as E5h. If all values ​​are equal to zero, and the system mistakenly reset the original data, this trick will reveal the error.

These are the basic principles of working with non-volatile EEPROM memory for Arduino microcontrollers. For certain projects it is worth using only this type of memory. It has both its advantages and disadvantages. To master writing and reading techniques, it is better to start with simple tasks.

Publications on the topic