I am using 25LC640A EEPROM with a 32 bit Micro controller. This EEPROM can store 8kb of data, with SPI serial Communication.

In my case during every power down sequence MCU will write some block of data into EEPROM and then it will shut down. And also its working fine. I have tested as many time as possible. No issues with EEPROM Data

Issue : But, Some times the EEPROM values got corrupted. My code throwing checksum error after turn on the MCU. i have checked code thoroughly, i am not able to find the bug since its working fine for so long time.

So any one here please suggest me what is the cause of this corruption of data. I have attached schematics also. enter image description here


What you are trying to do sounds reasonable, but this hints at something to look more carefully at:

power down sequence MCU will write some block of data into EEPROM and then it will shut down.

You have to be careful that the EEPROM is done doing the last write before you shut down power. EEPROMs can take ms to do writes. That's a very long time for even a modest microcontroller.

During normal operation, it's actually good to initiate the write, then let the chip go off and take its time while the software does something else. The software then only blocks waiting for the EEPROM to finish the write if another EEPROM operation is requested. In many cases, the write and other software operations overlap nicely. Even if another operation is requested immediately, that's never any worse than waiting explicitly after each write.

If you are using layered routines you didn't write, this may be how they work under the hood. In that case, the final shutdown needs to be handled differenctly. You make the call to do the last write, but then you must call something else that explicitly waits until the write is finished. Powering down before then will cause corruption. EEPROM libraries designed as described above will have a call that explictly waits for the EEPROM to be idle.


This can be caused by a faulty (or missing) brownout-reset circuit. When the MCU is operating at invalid Vdd voltage levels it can do just about anything, including going berserk and running random bits of code to write to an external EEPROM.

I highly recommend using a circuit (internal or not) that is guaranteed to inhibit the MCU's operation at invalid levels and is guaranteed to work down to a voltage at which the EEPROM cannot possibly perform a write (less than 1 volt will usually do it). It should stretch any glitch to long enough that the MCU is guaranteed to reset properly. The word 'guaranteed' is not used lightly- there are some internal MCU BOR circuits that are not guaranteed to work when you work out the tolerances and so on.

  • \$\begingroup\$ thanks for the answer. So you are saying that this Brownout-reset might happened during power down(Since i am writing data during shutdown) process ? isn't it?. (This corruption case rarely occurring other times its working perfectly ) \$\endgroup\$ – Photon001 Jun 25 '17 at 12:31
  • \$\begingroup\$ Brownout reset is what should happen. If it doesn't then corruption is more likely to occur during power-down because the MCU usually spends more time in that condition, and because even crappy reset circuits usually work on a sharp power-up if the unit has been off for sufficiently long. \$\endgroup\$ – Spehro Pefhany Jun 25 '17 at 13:37
  • \$\begingroup\$ All excellent points; another to consider is that if brownout is not protected against, it is perfectly possible for a write to violate a setup and / or hold time requirement, and then all bets are off. \$\endgroup\$ – Peter Smith Jun 25 '17 at 14:09
  • \$\begingroup\$ @PeterSmith Sure, as this is a serial (SPI) EEPROM it would manifest as garbled instructions or data. It's also possible the EEPROM itself could bugger up if a write is commanded and power goes out of spec during the erase+write cycles. That can be protected against by having enough reservoir capacity in the power supply (and possibly by implementing power down during the failure such as shedding heavy loads) that the EEPROM is guaranteed valid Vdd range during the longest possible erase-write cycle. \$\endgroup\$ – Spehro Pefhany Jun 25 '17 at 14:15

You mention that it has been working for a long time. I have had engineers not appreciate the number of lifetime writes of the device specification. With one million write cycles, if the uP does a write every second, the specification will be exceeded in less than 12 days. If it does a write every minute, the spec will be exceeded in less than two years. Once you exceed the specification, you should anticipate anomalies.

If you are convinced that it is not a lifetime issue, then you should add some diagnostic routines to dump the data, including the CS, when powering down and up. Run this in a test environment to see if you can spot the problem.

  • \$\begingroup\$ Thanks for your answer. I agree that it's not good write the eeprom data oftenly. But in my condition the power down sequence will happen only 2 or three times per day. In that case it won't exceed in that much early. But for me it's necessary to updates the eeprom for shutdown process \$\endgroup\$ – Photon001 Jun 25 '17 at 14:33

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.