# Amtel ATtiny EEPROM partially erased on power cycle

I have a Digistump with an Amtel ATtiny85 MCU. I can flash the MCU's EEPROM with an ISP programmer no problem. The chip works fine, the bootloader runs and the user program executes correctly.

Occasionally on power cycling a 200W Meanwell PSU the ATtiny will stop working. I dumped the EEPROM and compared it to the original Intel hex file. I noticed that the first handful of bytes are erased. See below. This doesn't happen all the time, just occasionally. I can reflash the chip but eventually this happens again.

If you think this is a defective chip, know that I have 30 of them from different suppliers and many of them exhibit this behavior.

Also, the Digistump is directly powered by the PSU. There are no USB data connections.

Question: Why does this happen?

Could a ripple from the PSU being shut off initiate a partial erasure?

### Solved:

The ATtiny85 has a Brown-Out Detect (BOD) circuit but it is disabled by default. There is a fuse calculator for AVR chips here. By setting the high fuse to 0xDD it activates the BOD threshold to 2.7V. With this enabled, EEPROM integrity seems to survive repeated power-cycling.

• Is there a brownout reset circuit that is a) present b) active c) set to appropriate voltages ? – Spehro Pefhany Aug 15 at 21:44
• No. None. The PSU, as seen on a multimeter, slowly decreases in voltage over the span of about a minute. I have a UPS-style shut-off circuit in mind (brownout off circuit), but I'd like to confirm if undervoltage or a ripple can cause this effect. – Drakes Aug 15 at 21:47

Such a slow decrease allows many possibilities for the MCU to "go nuts" and corrupt the EEPROM. It has enough supply voltage to do bad things (like write to EEPROM), but not enough supply voltage to operate reliably.

The same thing could happen with a relatively fast decrease, just less often, so you may be lucky to have caught it before it caused field failures.

A BOR circuit is the answer, hold it in reset whenever the supply voltage is out of spec for the clock speed and chip that you're using.

I don't recall if that particular chip has an on-board BOR and if it does, whether it works well enough, but external reset chips such as ADM805/809 variants work well provided you have the reset pin available.

• @Drakes ATtiny85 doesn't have a brownout circuit? It does according to the datasheet. – DKNguyen Aug 15 at 22:58
• It does. Setting fuses is new to me though. I’m in the process of setting the BOD fuses as we speak. Then I’ll monkey-test cycling the power supply and report the results. – Drakes Aug 15 at 23:00
• This was the right direction. By setting the high fuse on the ATtiny85 to 0xDD the BOR/BOD circuit is activated and set to a 2.7V threshold. – Drakes Aug 16 at 3:47
• @DKNguyen Is isn't because what level should it default to? – Jeroen3 Aug 16 at 6:15
• Enabling the Brown-Out Detector is correct here. Back in the days when AVRs did not have internal BODs, EEPROM corruption and especially the addresses starting from zero was a problem, since chip reset while writing would also set the EEPROM write address register to 0. One solution was to avoid the first page starting from 0, and after each write operation, set the address register to 0 for safety, so that accidental erase operations happen there. – Justme Aug 16 at 18:39