I've spent many hours trying to find a topic that may help me with my simple problem.
I want to burn a bootloader on an Atmel328P using my arduino uno. In order to do that I will need a 16MHz crystal. Unfortunately,I have searched in all the electronics stores here in Jordan. Non of them carry a 16MHz crystal. I know it's possible to buy one online, but it takes forever to receive it here in Jordan.
My question is how can I use a 20Mhz crystal instead of the 16MHz crystal.
I know there is a way, but I just can't seem to find the correct process of doing so.
I know it has to do something with the altering the bootloader hex files before actually burning them, but I can't find a simple how-to tutorial.
I tried to follow a tutorial that allows me to use the built in 8MHz crystal but for some reason, after adding the boards.txt file in a new 'hardware' folder in the arduino file is not allowing me to see the 'arduino on a breadboard' under the boards tab.
Therefore, I would like to know how to actually do it with a 20MHz crystal.
I apologize if this was a repeated topic and would appreciate a link to a topic that may cover my question.
I think you have to rewrite some of the Arduino system to handle this (millis/delay/micros/
pulseIn/Serial and so forth).
Then you have to figure out how to compile a bootloader using the corrected Serial code
so it talks at the right baudrate to download sketches.
I gave up trying to do this once, but it may be easier now. When I looked the time-critical
code all had conditional compilation for xtals of 8MHz and 16MHz but that was it.
You will be able to source a 16MHz crystal somewhere, its not an obscure value, eBay
will have them I'm sure.
Would you mind telling if a) it worked as described in the tutorial for you (if it doesn't we should try to get it changed) and b)if it works with the 20mhz crystal. (My guess is it wont, but its worth a shot...)
fkeel, i think your suggestion may work, but as i understood, you actually used a 16MHz crystal. but i dont have one in the first place. if i had one, i wouldnt mind keeping it in my design. i only have a 20MHz crystal and a 7.3MHz cyrstal.
MarkT, your on the right track, but what i am looking for are the instructions on doing so. i would love to be able to buy a crystal from eBay but its just not an option for me because of my geographic location.
EDIT: I think I figured it out. You should be able to use the 16mhz crystal for both controllers.
So, flip your Arduino upside down, solder two cables to the crystal, connect them to the XTAL pins of your other Atmega328p. Use the UNO to burn the 'barebones' arduino bootloader with internal clock sketch to it. Disconnect the crystal.
You should have a working barebones Arduino now.
EDIT 2: This link might help you if you want to use markt's method: AVR Tutorial - Fuses
@mohissa
My point is it might work without the crystal.
but... be creative:
If I understand you correctly, you have one Arduino UNO and one Atmega328p correct?
So you have two Atmega328p, one with a bootloader, one without. You also have one 16Mhz crystal. I feel like there has to be a way of solving this.
I would be interested to know if it works for somebody else.
The following is an uneducated guess, but I'd be curious of the results if you do give it a try:
If it does not work, I think there is an off chance that my method would work using one of your other two crystals. The reasoning behind this is that the data-rate of SPI is set with the SCK pin, so should be independent of whatever frequency the arduino is running at. I think its possible that all it requires is a timing source.
i am trying to try this tutorial: http://arduino.cc/en/Tutorial/ArduinoToBreadboard
but there is a problem. the attached Breadboard.zip file is either missing some files (it only contains a .txt file) or i am misunderstanding something.
from what i understand from the tutorial, i have to unzip the file, create a new 'hardware' folder in the arduino sketchbook folder and paste the contents of the zipped folder into the new 'hardware' folder. that should give me a new item in the Boards menu in the Tools toolbar. but it doesnt! this is my problem!
did you get a new item (ATmega328 on a breadboard (8 MHz internal clock)) as mentioned in the tutorial?
if so, how did you get to that point? (BTW, i tried it on both MAC and windows).
and yes, it makes a new entry. Make sure that capitalization is correct. Make sure that you are actually in the correct sketchbook folder (you can specify that by going into settings and manually selecting a folder as your sketchbook.)
thanks to you, fkeel, i was able to find my first problem. in my 'hardware' folder, i was supposed to create a 'Breadboard' folder. on my mac, when i unzip a file, it only shows me the boards.txt therefore, i assumed that i should put the text file in the 'hardware' folder.
having solved that problem, it took me a few tries until i got the bootloader burnt properly.
-i found that a 10K pull up resistor on the reset pin would really help. although the tutorial says its not required.
-You have to make sure you do the steps correctly:
1-upload the ArduinoISP sketch onto the arduino BEFORE connecting anything.
2-connect the wires according to the tutorial. make sure to connect the 3 'status' LED's (they help in letting you know whats going on exactly during the burning).
3-make sure to select the correct board type from the Tools menu i.e. "ATmega328 on a breadboard (8 MHz internal clock)"
4-choose the "Arduino as ISP" from the Tools-Programmer menu
5-click on the "Burn Bootloader" not upload!! (i did that mistake a couple of times because im just used to it)
thats it for burning the bootloader!
then you have to upload a sketch on the new bootloaded atmel. its pretty much the same as what you usually do with uploading a sketch on the arduino but with a few differences. after choosing the sketch you want to upload and rewiring according to the tutorial:
1-make sure you keep the "ATmega328 on a breadboard (8 MHz internal clock)" checked as your board from the Tools-Boards menu
2- same as step 4 above, the Arduino is still an ISP therefore, choose the "Arduino as ISP" from the Tools-Programmer menu.
then upload as usual.
remember, pins on the microcontroller DO NOT correspond to the arduino pins. here's the pin mapping for the atmel on the arduino:
in other words, when you are programming to blink pin 13 for example, you have to connect the LED to pin 19 on the micro controller.
i really hope this helps someone out there so that they dont have to go through what i went through!