This is a bit of a long introduction to the question...
I have a system with both an ATmega128 and ATmega2560. Each processor can be downloaded with new firmware in situ. As a complete fubar on my part I forgot to make sure the beginning of each file contain an indicator for which processor the file is intended. :oops: In other words, the user can accidently download the wrong firmware file into the processor.
Yeah, I know, stupid. Luckily, we haven't had this actually happen, and the external support software checks the file name before downloading. For the most part it won't happen.
But, I'd still like to throw in a last ditch "what if" in the code itself. Something that recognizes it is in the wrong processor and drops into the bootloader.
Now for the question: How would the code recognize the type of processor it is running in? There is a processor signature, but that appears to be accessible only from JTAG/ISP (unless my 3 readings of the datasheet missed it).
The only thing I can some up with is to do a subroutine call and look at how many bytes were pushed on the stack -- ATmega128 will push 2 bytes for the return address, while the 2560 will push 3.
Can anyone else see an easier method? Or, even better, is there a way to read the processor signature bytes from inside the processor?