I am working with AVR microcontrollers specially with Arduino for a long time. Arduino can be programmed in a number of ways. Because Arduino is open source and there are a lot of premade programs are available on GitHub, Instructables, Hackaday and Hackster. So, there are lot of programming software which supports different languages/ order and format.
But every piece of code is in the form of zero or one for the microcontroller. Once a program gets uploaded in the flash memory then there is no mean to recover the original. But we get the same program back from Arduino in Hex format. Now let’s have a look on hex files and how to recover your program from Arduino. This project is sponsored by PCBWAY.
HEX FILES:A HEX file is a hexadecimal source file typically used by programmable logic devices, such as microcontrollers in remote controls, office machines, and automobile engine control systems. It contains settings, configuration information, or other data saved in a hexadecimal format. This has one advantage over language code files that it cannot be edited until or unless you have the original language file code. Here I have a hex file in comparison with original file.
So, a user can use your file to make the project but cannot add anything extra to the program to make any changes in the overall projects. Even the assigned values and pin numbers can not be changed.
Generation of hex files from original file:You can see Sagar Saini’s article about “how to generate hex files using Arduino IDE”. from here to get knowledge about generation of a hex file in a very easy way.
How to Get back Hex files from Arduino:Here we need one extra microcontroller as programmer to retrieve the data back form target Arduino.
Upload the ARDUINO ISP code in the programmer Arduino keeping the programmer settings on USBasp using Arduino IDE.
Make the SPI data connection between the programmer and target Arduino board using the wire diagram given below.
Now Download and install AVRDUDESS program flashing software from here.
Open the software and select the programmer as Arduino, select your Arduino port and set the baud rate to 19200.
Now click on detect, it will automatically detect the microcontroller.
Set the fuse bits by reading, copy/paste them in a notepad file for future. These will help to upload the program correctly in the microcontroller.
Now in the flash section, click read option and then select the location where you want to save the file. Here I am saving this on desktop and naming as blink and extension as .hex. Keep in mind to set the format as Intel hex. Now click on Go button and it will take few seconds to generate the files properly. Otherwise, the software will show errors. Always select read when you are getting code back from Arduino and write when you are programming Arduino.
Sometime Arduino is programmed using EEPROM, so repeat the Same step for it but change the file extension as .eep.
You can see all the procedure of the programming in real time in the black tab named as compiler tab. After that you can see the hex files of your program on the selected location and you can examine them using Notepad or Notepad plus.
Now make the same connections with other target Arduino, where you want to flash these files. In this case I am using my 2nd version of Arduino UNO.
Now Open the AVRDUDESS, set the programmer as Arduino. Select the COM port and set the baud rate to 19200.
Detect the programmer, this will auto detect the programming board.
Browse the file location, Click on the Write button. Set the format as Intel Hex.
Then set the fuse bits and lock bits to the original position.
In the options menu select erase all the flash/ EEPROM before uploading program.
Click on GO, this will flash the Hex file to your Arduino.
Arduino used:Since I am working with Arduino, I designed my own microcontrollers in a better way. So that development boards are easy to use and program. You can see this article, how I made my own microcontroller development boards.
I ordered these PCB from PCBWAY, because the service and quality is best. You will get 5pcs of 2layer PCB in just $5 and if you sign-up to PCBWAY using this link you will get new user coupons to place the first order.
How to order PCB from PCBWAY.First, Go to PCBWAY and sign-up using this link. Click on instant quote and choose the designed PCB dimensions, If wrong then corrected by the team of engineers.
Select the quantity, thickness, color, material and Finishing type.
Calculate the PCB cost and then save it to cart.
Upload the Gerber file, now engineers will inspect the PCB dimensions, tracks and type and give you the final quote (This will take 5 to 10 minutes).
Checkout and get your PCB just in 7 days at home.
Comments