We managed to make upload programmes in our micro controller. It wasn't easy at all. And after we managed to do is I wrote a guide for you guys so you can do it yourselves. I hope you enjoy it.
Here it is!
1 The goal of this guide
After reading the short guide you should be capable to load up your own program(written in Arduino). To a atmega328 connected to a 20MHz cristal.The longer guide explains how you can adjust the board.txt file and avrdude.conf file to a microchip of your choice. In this guide you will learn what to adjust an how. In the short guide this is already done for you. The long guide is an extension to the sort one.
2 Short guide
2.1 Getting started(prepare yourselves)
First make sure that you can connect the reset, MOSI, MISO and SCK pin easily to the Arduino and that you can supply the microcontroller with a 5V or 3,3V stabilized voltage.Download WinAVR, you can use the link below or you can look for it yourself. http://winavr.sourceforge.net/download.html
After downloading WinAVR you may install this program. We will need this later on.
2.2 Checking for a signature(look if it is alive)
After you made sure all this is possible, you may open an empty Arduino file.Go to ‘File’ -> ‘Examples’ -> ‘ArduinoISP’
(You can go ahead and read this file because some of this guide is based on the text above the program.)
After you did this you may connect the three leds as the text in the program asks you to do. After this you ma upload the program in your Arduino. (check your board en serial port first).
Once the uploading is done you should have one of the three leds (the one on pin9) glowing softly. This is your heartbeat. If this led ever burns constantly then you should reset the Arduino your working on. This may or may not be necessary later on. It depends on how lucky you are.
After all this is done you may change the settings of the Arduino software to:
- ‘Tools’ -> ‘Board’ -> ‘atmega duemilanove w/ATmega 328’ (it has to be this regardless of what board you’re using.)
- ‘Tools’ -> ‘Programmer’ -> ‘Arduino as ISP’
- ‘File’ -> ‘Preferences’ -> Mark the checkboxes ‘compilation’ and ‘upload’
This is all for the software. You already connected the three leds to pin 7,8 and 9 of the Arduino (except when you’re using a MEGA check the text above the Arduino ISP program to see which pins you should use).
Now, connect the MOSI, MISO, SCK and reset pin according to the following table (again this table is NOT for Arduino MEGA’s check the text above Arduino ISP for that!!):
Pin Controller Pin Arduino
Reset 10
Mosi 11
Miso 12
sck 13
NOTE: make sure the ground of the Arduino and the microcontroller are connected. It won’t work if these aren’t connected!!
Once this is done the hardware and software parts are all ready to check if the microcontroller is alive.
Go to ‘Tools’ then click ‘burn bootloader’. IT WONT WORK! So don’t panic. You’ll get (if everyting goes as planned) this error. The printscreen was taken at the bottom of the errorlist under the progrmcode of the arduino software. You can see (aproximately halfway this picture) ‘device signature = 0x1e9514’ this is a good sign. When a microcontroller answers with it’s signature it works just fine. Next step, we are going to adapt the software to our needs.
2.3 Adapting the software to our needs
You can find two files you need to download on our blog (http://auto-3am-gr9.blogspot.be/). It will be under the subject where you found this guide. (in these folder the changes have been made for a atemega 328 with a 20MHz crystal. The long guide learns you how to do this so you can do this for yourself and maybe other microcontrollers.)Now I will tell you where these folders need to be replaced.
2.3.1 Board.txt
Go to the folder where you’re Arduino software is located. Once inside this folder go to ‘hardware’ -> ‘arduino’ you can see the board file there. Just copy the new one in this folder and replace it for the old one. Close this window.2.3.2 Avrdude.conf
If you installed WinAVR correctly (like I asked in the beginning of this guide) the you sould find a folder named ‘WinAVR-20100110’ on your primary hard drive. Open this folder and go to ‘bin’. In this folder you will see the Avrdude.conf file (if you look hard enough or use Ctrl-f..). Now replace this folder with the one you downloaded from our blog. Close the window.NOTE: close all windows of Arduino software so it can adapt to the new board file!
After you did this we are done adapting the software!
2.4 Adapt the Low fuse of the microcontroller
This is where the fun starts. We will now start controlling the controller.Open cmd. Now type in the following command ‘avrdude –P com?? –b 19200 –c stk500V1 –p m328g -v -v’
Fill on the ?? the serial port which you’re Arduino is currently using.
This should sum up some facts of your microcontroller. You should get something like the picture below
On the bottom of this picture (and hopefully you cmd screen) you can see that the device signature is still there (lucky us, it’s still alive) and under the signature you van se ‘lfuse ready as 62’ this means (among other things) that the microcontroller is running on his internal clock of 1MHz. We don’t want this because is screws up all our programs. We want it to run on the 20MHz crystal. This is what we are going to do:
Type in the following command: ‘avrdude -P com?? -b 19200 stk500V1 -p m328g -U lfuse:w:0xFF:m’. Again, the question marks are to be replaced by your serial port. BEFORE YOU PRESS ‘ENTER’ MAKE SURE THAT I’TS lfuse AND NOT hfuse!!!!! If you write hfuse you will lock down the microswitch forever.
Now we are sure that things are correct, press enter. You should get a screen like the picture below.
The microcontroller is now ready for us to put a program on it.
2.5 Uploading the software
Open the software you want to upload. Do this with Arduino. If everything went according to plan (or guide..) then go to ‘Tools’ -> ‘Boards’ -> ‘ATmega328 van Glenn’. Set the programmer to ‘arduino as ISP’. Also check if the checkboxes in ‘file’ -> ‘preferences’ are still on.Now click on COMPILE!! Not upload, you will ruin everything.
NOTE: If you did click upload than repeat ‘checking for a signature’ to check if everything is still working and repair the mistake you made.
After you clicked on compile, you should see a lot of stuff going on in the black screen below your program. After it is finished you should see something like the picture below on the bottom of that screen.
If we magnify it, it looks like this:
Now open cmd again. The file path you see highlighted in bleu is this guide is specific for our computer so don’t copy this file path, use the one you have on your screen.
You can go to a file by using the ‘cd’ command. Look at the pictures below to see how we did it.
Again, this is the file path for our computer, don’t copy this completely it won’t work.
Now, once you are in the correct build map you can check if your file is in this file. You can do this by using the command ‘ls’ as you can see in the picture below.
Once you made sure it’s there type in the following command: ‘avrdude –P com?? –b 19200 –c stk500V1 –p m328g –U flash:w:??.cpp.hex
For the first pair of questionmarks, fill in the serial port of your Arduino. For the second question marks check your compiled file on Arduino to see what the name of the file is and fill it in. (please use ‘.cpp.hex’ only once)
Press enter and if you obeyed this guide as you should have done then you should see the program uploading on your microcontroller.
3 The end
Thank you for using this guide I hope you’ll enjoy it!I would like to thank the team that made most of this possible. So thank you Laurens, Glenn and Mathijs
I would also like to thank my team. Thank you Stef, Stef and Réné.
And finally I would like to thank the lector who helped us, thank you Mr. Lievens
NOTE: sorry for mistakes I may or may not have made against the English language, I’m from Belgium so English isn’t my native language.
Brought to you by
Giete
Geen opmerkingen:
Een reactie posten