Getting a .hex (or other compiled) file FROM a chip

I've searched for a while and cannot find a straight answer for this, hopefully someone can help me.

I basically have a programmed ATMega chip that I want to duplicate onto another ATMega of the same model.

I want to pull the hex file from the first chip onto the second chip as I do not have the source code for the chip.

I am pretty sure I can put the hex file onto the new chip, but I have no idea how to pull it from the first chip.

If anyone can help me I would really appreciate, I'm wracking my brain over this!

I'm assuming you have a programmer?

Using avrdude something like this:

avrdude -c usbtiny -p m328p -U flash:r:myfile.hex:i

You may need to change "usbtiny" to match your programmer type, and "m328p" to match your chip type.

The ":r:" near the end reads the flash and saves to myfile.hex.

To write this file to a new chip:

avrdude -c usbtiny -p m328p -U flash:w:myfile.hex

The ":r:" (read) has changed to ":w:" (write).

[quote author=Nick Gammon link=topic=155905.msg1168502#msg1168502 date=1364003032] I'm assuming you have a programmer?

Using avrdude something like this:

avrdude -c usbtiny -p m328p -U flash:r:myfile.hex:i

You may need to change "usbtiny" to match your programmer type, and "m328p" to match your chip type.

The ":r:" near the end reads the flash and saves to myfile.hex.

To write this file to a new chip:

avrdude -c usbtiny -p m328p -U flash:w:myfile.hex

The ":r:" (read) has changed to ":w:" (write). [/quote]

Thank you very much! I'm working off of a Sanguinololu board, I'm guessing I'll have to find supporting files before I can use AVRdude with it?

Thank you very much! I'm working off of a Sanguinololu board, I'm guessing I'll have to find supporting files before I can use AVRdude with it?

AVRDUDE through it's avrdude.conf file supports the 644P chip already so you shouldn't need any 'support files', just a hardware programmer that avrdude can work with.

Lefty

avrdude will do this, unless the flash in the source chip has been protected. For reading flash to an intel hex file, it would look like:

    avrdude ... -U flash:r:myfile.hex:i

oops. Since I've been beaten to the punch, I'll point out that it SHOULD be possible to do this via the bootloader as well (which may well give you a .hex file that contains both sketch AND bootloader.)