Copy microcontroller

Hello sorry for the not so informative topic title.

Lets say i have lost my backups and would like to retrieve my code from the microcontroller. From what ive read this is not possible since the code is compiled etc. But would it be possible to copy the compiled code on an atmega168 for example and load it into another atmega168 without actually retrieving the code. Like extract the compile code and put it in a new fresh microcontroller. Anyone here who have any thoughts on that?

Best Regards Lassemajsan

Yes, one can use a program like AVRDUDE to read back the binary contents of the flash memory back into a Intel hex file and then use AVRDUDE to write it back again into the same type of chip. However it will only execute correctly if the new target device is used in the exact same manner, same clock speed, same pins used, etc.

Lefty

Should be possible to copy the binary (compiled) code, with AVRDUDE. I've done it with EEPROM, but not with the flash (program) memory. But it should be the same process, download to a PC, then upload to a second microcontroller. But there is no getting the source code back.

Cool! Thanks for your reply, i will definatley look into this. Might be a stupid question, but there is no need to put an arduino bootloader on the new chip before the code from the old mc is loaded into the new chip right? And also would the fuse settings from the old chip be included in the "binary contents"?

lassemajsan: Cool! Thanks for your reply, i will definatley look into this. Might be a stupid question, but there is no need to put an arduino bootloader on the new chip before the code from the old mc is loaded into the new chip right? And also would the fuse settings from the old chip be included in the "binary contents"?

No a bootloader is not required to load the contents of the hex file onto a new chip IF you are using the ISP programming method.

Fuse content is not part of the flash memory that is written or read from the chip. However AVRDUDE does have the ability to read and write fuse information as separate operations.

Lefty

Thanks for the info! Im going to perform som experiments on this soon. Is there anything more that needs to be copied besides copying the flash memory and fuse settings? Gonna rea the avrdude manual now :)

lassemajsan: Thanks for the info! Im going to perform som experiments on this soon. Is there anything more that needs to be copied besides copying the flash memory and fuse settings? Gonna rea the avrdude manual now :)

Well if the original sketch uses the chip's EEPROM memory and there is valid data in the EEPROM memory, then that too would have to be read and then written. Again that too is something that can be done with AVRDUDE.

Lefty

retrolefty: Yes, one can use a program like AVRDUDE to read back the binary contents of the flash memory back into a Intel hex file and then use AVRDUDE to write it back again into the same type of chip. However it will only execute correctly if the new target device is used in the exact same manner, same clock speed, same pins used, etc.

For his own programs, I guess this shouldn't be an issues, assuming copyprotection fuse bits weren't set, right ? I think I read something like that a while back, but could've been in the context of another uC though.