1. Program problem;
2. Program runaway;
3. EEPROM related registers are written incorrectly due to external interference such as strong magnetic field, high voltage static electricity, etc.;
4. The system has a large inductive load, which will generate a reverse high voltage when the power is off, and the EEPROM may be self-erased.
... (If there are any other reasons, please continue to list them so that we can improve and find a solution)
Regarding problem 1, the program problem is no longer within the scope of this article.
Regarding problem 2, the program runaway should be the main reason for EEPROM data loss. However, there are many reasons for program runaway.
First, the voltage is abnormal, the work is unstable, and the program runs away. To solve this problem, you can turn on the internal BOD or add an external reset chip to solve it. In low-power occasions, external reset is
necessary , after all, the BOD power consumption is too high.
Second, the crystal oscillation is disturbed, the frequency is unstable, and the program runs away. To solve this problem, it is recommended that the crystal use full-range oscillation, and the routing should be as short as possible, and use ground wire isolation.
Third, the system is disturbed by the external environment, and the PC and other registers are modified, and the program runs away. Regarding this interference problem, the possibility of causing the program to run away should be small. If the environment is really bad
, then you should think of doing electromagnetic shielding, ESD protection, etc. If it still doesn't work, then we can only suggest changing to another microcontroller.
Regarding problem 3, we can only optimize the circuit settings and try to avoid it, such as adding a shielding cover, adding ESD protection, adding TVS protection, adding capacitor decoupling to the power supply, etc.
Regarding problem 4, if the system really has a large inductive load, then pay attention to adding freewheeling diodes, filter capacitors, etc. for protection, and do not allow this reverse high voltage to be generated. In any case,
this high voltage generated by the sudden power failure of the inductive load will not only affect the EEPROM, but also pose a threat to the entire system.
================================================== ================================================== ==========
After the above hardware processing, although the possibility of EEPROM data
loss is very small, we still cannot guarantee that EEPROM data will not be lost. At this time, the reliability of EEPROM data must be considered from the software aspect. Then we
will continue to discuss from the software aspect.
My approach is to block, partition, verify and backup the data. Of course, the processing method mentioned here is just to provide an idea. You can do block with different data lengths,
partition with different sizes, use different address mapping methods, and use more data backups. Let's continue to discuss with Mega168 as an example.
1. Mega168 EEPROM 512 bytes, divide the EEPROM into two areas, each area is 256 bytes, and then use 8 bytes as a segment, so each area has 32 segments.
Data area: 0x000 - 0x0FF
Segment 0: 0x000 - 0x007
Segment 1: 0x008 - 0x00F
...
Segment 31: 0x0F8 - 0x0FF
Backup area: 0x100-0x1FF
Each segment has 8 bytes, of which the first 6 bytes are valid data and the last 2 bytes are CRC16 checksum. The data format is shown in the figure below:
2. EEPROM read and write operations
EEPROM operations are performed in segments.
Segment write function: when writing data to the data area, first calculate the data CRC16 checksum, and then write the data to the data area and the backup area at the same time;
segment read function: when reading data, read the data area and the backup area at the same time. If the data area checksum is incorrect and the backup area data checksum is correct, use the backup area data to restore the data area data;
if the backup area data is incorrect and the data area data is correct, then write the data to the backup area and back it up again; if both the data area and the backup area data are incorrect, then return to read failure.
3. Correspondence between the data area and the backup area
Data read and write operations are performed in segments. How are the internal data area and the backup area mapped? In order to prevent the data and the backup from being accidentally modified at the same time, the data and backup address spaces cannot be
too close , and the addresses of the data and the backup should be as different as possible. Assuming the data address is Data_Addr and the backup address is Bakup_Addr, I use the following function to map the address:
Bakup_Addr = (Data_Addr + 0x100) ^ 0x03F
plus 0x100 defines the address to the backup area, and XOR with 0x03F is to invert the lower 6 bits. In this way, the data and backup address spaces are far away, and the addresses are 7 bits different.
For example, the address of the third segment: 0x018 - 0x01F,
the corresponding backup area is: 0x127 - 0x120
as shown below:
4. Add write protection judgment to the read and write functions, turn off the write protection before reading and writing EEPROM, and turn on the write protection immediately after reading and writing. This can effectively prevent accidental modification of EEPROM caused by program running away
.
5. It is recommended not to use block 0.
Previous article:A balancing system based on Mega128 encoder to control stepper motors
Next article:Design of avr0~5V digital DC voltmeter
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- Brief Analysis of Automotive Ethernet Test Content and Test Methods
- How haptic technology can enhance driving safety
- Let’s talk about the “Three Musketeers” of radar in autonomous driving
- Why software-defined vehicles transform cars from tools into living spaces
- How Lucid is overtaking Tesla with smaller motors
- Wi-Fi 8 specification is on the way: 2.4/5/6GHz triple-band operation
- Wi-Fi 8 specification is on the way: 2.4/5/6GHz triple-band operation
- Vietnam's chip packaging and testing business is growing, and supply-side fragmentation is splitting the market
- Vietnam's chip packaging and testing business is growing, and supply-side fragmentation is splitting the market
- Urgently looking for expert advice AD15 can not open the PCB after cracking
- Difference between LPS22HH and LPS22HB
- How to collect multiple sensor signals through one RS485 interface of industrial computer?
- Altera SoC Architecture Excerpt - What is a SoC FPGA
- How to use common mode chokes in signal lines to eliminate common mode noise
- EEWORLD University ---- Python 3 video tutorial
- [Rivet RVB2601 Creative Application Development Competition] Participation Award Prizes
- CCS5.5 compiler optimization issues
- Is there anyone who knows PGA460? My circuit diagram is based on PGA460PSM, but I can't get any measurement results.
- How does AD import the complete content of a DWG file, or how does AD apply copper in a ring-shaped strip area?