I've written an I2C bootloader in C that's mostly working except, so far, for one thing: when there are I2C communication errors during the transmission of the user application from the I2C master, the bootloader makes a "safety flash erase" (this is by design) but, after trying again to transmit-flash the application, it writes garbage on the first page of the flash.
However, if I do a power-on reset after erasing, the application is flashed correctly.
Then I have two questions:
- How should I initialize by code all things related to self-programming after erasing memory, before retrying to write again? (registers, temporary page buffer, etc). If you have code examples, I will appreciate it.
- What things are recommended to initialize in general to imitate a reset on the Tiny 85? At the moment I'm only disabling the watchdog and the interrupts.
Thank you very much for your help!