How can I a catch an unexpectedly reset in a microcontroller
<p>I'm working with a MCF51EM256 Freescale microcontroller and I've some problems with the flash programming. </p>

<p>In order to make my software persistant I'm trying to store some variables in the external flash memory to recover from unexpected shutdowns.</p>

<p>Sometimes, when I test my work shutting down the MCU, it is constantly reset. It is probably caused by an error writing any flash address, during the shutdown, which after is not able to read properly.</p>

<p>My question is, there is a way to catch this fatal exception which causes the reset in my micro?</p>

<p><a href="http://cache.nxp.com/files/32bit/doc/ref_manual/MCF51EM256RM.pdf?fpsp=1&amp;WT_TYPE=Reference%20Manuals&amp;WT_VENDOR=FREESCALE&amp;WT_FILE_FORMAT=pdf&amp;WT_ASSET=Documentation&amp;fileExt=.pdf" rel="nofollow">MCF51EM256 Reference Manual</a></p>