Blog of TahomaSoft.com

Misadventures in Microprocessor Cloning

Erik Beck

I recently purchased an electronics kit to build a component tester (capacitors, resistors, diodes, transistors and inductors). While putting it together, I experienced issues installing the ATMEGA 328p chip into its socket, breaking off one of the 28 leads. Half-luckily, that broken lead (pin 28) didn’t seem to impact the main function of the board, although it may be responsible in part for giving bogus low-battery warnings.

I bought the board on clearance sale; it has been discontinued by the manufacturer for some time. And the manufacturer’s support site wasn’t great; I had to contact them to remove an IP-Geo block to North America so I could download the assembly and usage manuals. So figuring getting a replacement part was unlikely, and with the source code not available, I came up with the bright idea to try cloning the programming to a new 328p; they are still reasonably easy to get at about $2.50 each.

First step on this journey was to get an in-system programmer (ISP) for the ATMEGA to copy off the code from the bunged-up chip and put it on a new chip. It took some trial and error to hit on the right combination of programmer and target arrangement to get this to work for me. I tried putting the target on a breadboard and using a TinyUSBisp (from HiLetgo via Amazon.com) as the programmer. Avrdude was able to access the TinyUSBisp programmer, but reading the contents of the chip off the breadboard was problematic (note I also used some pre-programmed ATMEGA 328p chips from Arduino Uno and clones to try and work out the methodology). This was using the simplest possible wiring from the programmer to the chip, without an external crystal, resistors, capacitors, etc.

Next attempts were at using an Arduino Uno instead of the TinyUSBisp as the programmer, with the chip again on a breadboard. I tried various wiring arrangements, with and without a 16MHZ crystal, resistors, and capacitors. This also didn’t work well (but later I noticed that I used a very wrong pair of capacitance values).

What worked best for me was using the TinyUSBisp as the programmer, and wiring it up to an Arduino Uno from which the usual 328p chip was swapped out for the target chip. This generally worked; I was able to read and write to practice chips fine. Initially, reading the flash from the chip with the missing leg seemed to work fine; but on further inspection, I discovered the lock bits were set, and so all the chip would give up to avrdude for the flash data were a bunch of 0xFFs; avrdude does not raise an error if the lock bits are set, it just won’t work correctly.

So I did what I could to make the damaged chip run as well as possible in the component tester kit.

And next time I need to program a 328p, I’ll probably start with the TinyUSBisp -> Arduino, but will give the breadboard arrangement, with the right capacitors this time, a try.