Sunday, 26 May 2013

Arduino revival with EPROM programmer

This is an old post, preserved for reference.
The products and services mentioned within are no longer available.

One of the errors you get from time to time when working with Arduino's in general is

avrdude: initialization failed, rc=-1
Double check connections and try again, or use -F to override this check.

This error covers a multitude of sins. 99% of the time it is due to the chip not being connected to the programmer correctly for whatever reason. Either it is missing, badly inserted or there is a wiring problem between the chip and the 6 pin header. To fix those sort of problem, check the wiring, and don't bother with -F, that could just lead to more trouble.
In this case, I'm in the other 1%. I know the wiring is correct because I was using a USBtinyISP plugged into an Arduino UNO board, and it had been working correctly. The error in this case is because I had been setting the fuses via avrdude on the command line and I had programmed a duff set of fuses into the chip, setting a stupidly low clock rate. In this state, the ATMega328P wasn't able to handle interfacing with the programmer (but it was probably running in a low power mode which is what I was trying to achieve).

I tried various solutions to this, apparently adding -B10 (up to -B250) is meant to help by slowing the interface down, and indeed it did, a bit. It got through the chip ID, but failed on the next step. One thing I didn't get around to trying was injecting an external clock into the chip, which might have worked. However, I was keep to get on with the battery powered LCD clock I was working on (more about that later...), so put that chip to one side.
Later I remembered I'd bought a cheap 'universal programmer' from ebay in order to program some EPROMs. After the fun I'd had with the VIC20 repair, I had concluded I needed a new one. The MiniPro programmer seemed quite widely available and had decent reviews. It has a massive list of supported chips, including some neat features like testing 74 series logic chips and SRAM chips. It also had the option to program various microcontrollers. I wasn't planning on using it to program ATMega328Ps, as I normally work in the Arduino IDE, which has no support for this, but easy support for programming using the standard bootloader on an Arduino board, or with the USBtinyISP.
Firing up the software, it read the chip correctly and showed the duff fuse settings. I was able to set them back to something more reasonable and reprogram the chip. To make sure it was OK, I changed to a known working ATMega328P and read that in, saving a copy for future reference. I then wrote the code and fuse settings from the working chip back to the dodgy one. That seemed to go alright, so I replaced the chip in the Arduino Uno board, loaded the IDE and programmed it with the blink example (what else).

The moral of the tale, when it says 'be careful when setting fuses', it means it!