Backup bootloader of ATMEGA16

I have an ATMEGA16 lying around that was in an old robot I'd bought. It was in a socket, so I pulled it out and was thinking of using this page to use it with Arduino IDE. Is there a way for me to backup the chip's current state, so as to be able to restore it if I mess up?
I don't have an SPI programmer with me, but I do have a Arduino Uno available at hand

Arduino running arduino as ISP sketch gets you the spi programmer. One of the MCUdude board packages supports atmega16.

That diagram omits the required decoupling capacitors (0.1uf ceramic right next to chip between vcc and gnd),

Use avrdude from command line to dumpflash contents to a .hex and output fuse values.

Then proceed!

DrAzzy:
Arduino running arduino as ISP sketch gets you the spi programmer. One of the MCUdude board packages supports atmega16.

That diagram omits the required decoupling capacitors (0.1uf ceramic right next to chip between vcc and gnd),

Use avrdude from command line to dumpflash contents to a .hex and output fuse values.

Then proceed!

Do I have to remove the onboard microcontroller on my Uno?
Also, the minimal configuration files are for ATMEGA328. Where can I find them for ATMEGA16?

You may not be able to dump the flash, I have not checked the datasheet but most atmega chips can be set so that the flash cannot be read to keep people from duplicating/examining the code.

If you want to program the chip through the Arduino IDE, there is support for the atmega16 in MCUdude's MightyCore.

david_2018:
You may not be able to dump the flash, I have not checked the datasheet but most atmega chips can be set so that the flash cannot be read to keep people from duplicating/examining the code.

If you want to program the chip through the Arduino IDE, there is support for the atmega16 in MCUdude's MightyCore.

Is there a way I can check if the chip has been set unreadable by bot manufacturers

You can just try to perform a read to see if you can access the memory.

Run this command to perform a flash dump with Avrdude. Note that you'll have to replace the Avrdude path, config file path, and the COM port number. If you're not sure what your Avrdude and config file path is, you can copy them from the Arduino output if you enable verbose upload in the IDE settings.

/path/to/avrdude -C/path/to/avrdude.conf -v -patmega16 -cstk500v1 -PCOM4 -b19200 -U flash:r:flashdump.hex:i

If you want to use the ATmega16 with Arduino IDE, you will have to install MightyCore :slight_smile:

I managed to load the Arduino bootloader into the chip. The blink program worked successfully using my Uno as FTDI (https://www.arduino.cc/en/Tutorial/ArduinoToBreadboard). However, when I try to use the USB port (Prolific PL2303) builtin my bot, it says:

 avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding

Another observation: As soon as I click upload, the LED, which had been blinking due to blink program, it stops blinking.

Here's the link for my bot's documentation: www.technogravity.com/products/qu_bot/qu_bot_downloads.php

Wow, that's some great hardware to run Arduino code on! If you'll ever run out of memory there are several drop-in replacements that will be 100% compatible with the ATmega16.

Another observation: As soon as I click upload, the LED, which had been blinking due to blink program, it stops blinking.

That is not strange at all, it's very much expected behavior. When the bootloader is first loaded it loops over and over again, and is just flashing an LED twice a second. As soon as the microcontroller gets a hard reset pulse from the USB to serial adapter, it will no longer loop, hence the dark LED.

You are not able to upload using the built-in PL2303 because the auto-reset circuity is wrong. If you look at the MightyCore minimal setup schematic, you can see that the capacitor on the RST pin on the ATmega16 is supposed to be wired in series with the DTR pin on the PL2303, and not be tied to ground.

Lucky for you, almost all components on the board are through-hole. All you need to do is to cut the DTR line that's connected to the RST pin on the ATmega16, desolder capacitor C3, and connect this in series with the RST line instead. If it still fails or the chip becomes unstable, you will probably have to add a 10k pullup resistor to the RST line.

For reference, here's the schematic for your hardware:

... and here is the MightyCore minimal setup:

Hope this helps!

hansibull:
Wow, that's some great hardware to run Arduino code on! If you'll ever run out of memory there are several drop-in replacements that will be 100% compatible with the ATmega16.

That is not strange at all, it's very much expected behavior. When the bootloader is first loaded it loops over and over again, and is just flashing an LED twice a second. As soon as the microcontroller gets a hard reset pulse from the USB to serial adapter, it will no longer loop, hence the dark LED.

You are not able to upload using the built-in PL2303 because the auto-reset circuity is wrong. If you look at the MightyCore minimal setup schematic, you can see that the capacitor on the RST pin on the ATmega16 is supposed to be wired in series with the DTR pin on the PL2303, and not be tied to ground.

Lucky for you, almost all components on the board are through-hole. All you need to do is to cut the DTR line that's connected to the RST pin on the ATmega16, desolder capacitor C3, and connect this in series with the RST line instead. If it still fails or the chip becomes unstable, you will probably have to add a 10k pullup resistor to the RST line.

For reference, here's the schematic for your hardware:

... and here is the MightyCore minimal setup:

Hope this helps!

I'm a bit new to electronics with zero knowledge of PCB design. Googling up guides for how to read schematics, this is what I understood: The reset pin of atmega is connected to a switch, then to a capacitor and then to GND. Am I right? Could you please explain what to do next in beginner terms

I'm a bit new to electronics with zero knowledge of PCB design. Googling up guides for how to read schematics, this is what I understood: The reset pin of ATmega16 is connected to a switch, then to a capacitor, and then to GND. Am I right? Could you please explain what to do next in beginner terms

The only thing that's different is labels. You can see that pin 9 on the ATmega16 has a label (on the green wire) that says RTS. Pin 2 on the PL2303 also has a label saying RTS on pin 7. This means that these are connected. Simple as that.

hansibull:
The only thing that's different is labels. You can see that pin 9 on the ATmega16 has a label (on the green wire) that says RTS. Pin 2 on the PL2303 also has a label saying RTS on pin 7. This means that these are connected. Simple as that.

The switch S1 also seems to be connected to RST

So, is it like a 3-wire junction?

The switch S1 also seems to be connected to RST

Yes, you can use that to perform a manual reset, just like on a standard Arduino board. But you will have to do the modification to the board if you want to upload code using the USB adapter on the board.

hansibull:
Yes, you can use that to perform a manual reset, just like on a standard Arduino board. But you will have to do the modification to the board if you want to upload code using the USB adapter on the board.

Had the reset been the problem, shouldn’t the upload have worked if I manually reset it just before uploading?

Which bootloader did you install on the chip, and do you have the exact same settings under Tools > Board in the Arduino IDE as you used when installing the bootloader? When you installed the bootloader, did you set Tools > Board > Clock to External 7.3728MHz?

david_2018:
Which bootloader did you install on the chip, and do you have the exact same settings under Tools > Board in the Arduino IDE as you used when installing the bootloader? When you installed the bootloader, did you set Tools > Board > Clock to External 7.3728MHz?

I used the "Arduino as ISP" guide. And yes, I've been using the settings you mentioned

Had the reset been the problem, shouldn't the upload have worked if I manually reset it just before uploading?

Technically, you may be able to get the reset pulse right by using the physical reset button. But it's difficult, and the modification you could do is dead simple and takes you only a few minutes. After this mod, your robot will act exactly like an Arduino. I don't see why you wouldn't want that.

hansibull:
Technically, you may be able to get the reset pulse right by using the physical reset button. But it's difficult, and the modification you could do is dead simple and takes you only a few minutes. After this mod, your robot will act exactly like an Arduino. I don't see why you wouldn't want that.

Actually, being new to Arduino, I have zero experience in PCBs and soldering. Moreover, due to this covid-19 lockdown, it isn't possible to purchase a soldering kit either. Could you please provide a temporary solution till the situation normalises?

devmrfitz:
Actually, being new to Arduino, I have zero experience in PCBs and soldering. Moreover, due to this covid-19 lockdown, it isn't possible to purchase a soldering kit either. Could you please provide a temporary solution till the situation normalises?

Also, after a lot of trial and error, I'm sure this is the source of the problem: When I click upload in IDE, the reset pin gets shorted to GND and stays shorted unless the upload completes.
What is supposed to happen: Pin should be shorted and then normalised after a moment so that ATMEGA resets

Also, after a lot of trial and error, I'm sure this is the source of the problem: When I click upload in IDE, the reset pin gets shorted to GND and stays shorted unless the upload completes.
What is supposed to happen: Pin should be shorted and then normalized after a moment so that ATMEGA resets

Yup, that's how it behaves when the DTR line from the PL2303 is connected directly to the reset pin on the ATmega16. A capacitor in series (together with a pullup resistor), as I've mentioned earlier will turn this into a short low pulse instead.

If you have no tools available that will help you do this modification to your board I suggest you use the 6-pin ISP connector to upload code until you get the tools to perform the mod.