Electrical – EEPROM Values Corruption – Only Some times

eeprommicrochipmicrocontroller

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

Best Answer

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.