I'm sure this question has been answered somewhere before, but I am getting really confused googling around for my answer so I thought I'd ask the experts directly.
I have an Arduino UNO, and an ATMega328P-PU. I want to be able to load regular avr programs onto the ATMega using only the Arduino [no crystal or capacitors](I have a usbasp programmer on order but that will take 3 weeks to get here), but I'm confused as to whether I need a bootloader or is that for a different purpose?
Do I need different wiring? Do I need a bootloader here? Do I need to change the command I send to avrdude (I changed the m168 to m328p)?
My goal is to start learning more about avrs since I am doing my thesis this year and will be working on a telemetry system for a UAV with an XMega and XBees + Processing. I want to be able to firstly put a program on the ATMega328P-PU I have, then when I'm comfortable with that I'll connect one of the two NRF24L01s RF modules I have to it, and another to my Arduino to simulate my telemetry setup sending data back and forth wirelessly(I start my thesis in a month).
Any guidance for setting up my ATMega or anything else in my post would be greatly appreciated.
I was following the hackaday tutorial which did not mention anything about it but I now see that he is using a dueminalove. I used the arduino.cc page only for the wiring diagram.
So this is all I will need to do then, all the other steps are right for uploading simple .hex programs to the atmega328p-pu? I will try the hackaday tutorial again but with the 10uF capacitor, and the exact circuit shown on the bottom left of the arduino.cc tutorial.
And do I just use '328p' in avr dude even though my atmega has 'pu' at the end?
I just tried the exact configuration (bottom left diagram and with a 10uF capacitor from ground to reset) on the arduino.cc website for ArduinoISP, but I am getting the same "Yikes .. Invalid Device Signature" problem.
Could it be that I need a crystal (16MHz)? I thought it was unnecessary with that configuration?
I will post verbose output tonight when I get home.
These are the steps I took to upload a hex file to my atmega328 using my Arduino UNO as an ISP:
Installed the latest WinAVR which comes with avrdude.
Connected Arduino to PC, uploaded ArduinoISP using Arduino IDE 1.01 [board selected is the UNO].
Wired up my atmega exactly like this:
Downloaded "main.hex" from this page http://hackaday.com/2010/10/25/avr-programming-02-the-hardware/ under heading "Flashing firmware with AVRdude
" - this is supposed to be a program that blinks an LED. This is what it looked like except I had 5V running from the Arduino to the 5V rail like in the picture above and GND from the Arduino to the GND rail (and no other power source).
[This is a picture from the hackaday website, not one that I took]
Opened up command prompt, navigated to the directory with the .hex file, and used: avrdude -P COM7 -b 19200 -c avrisp -p m328p -U flash:w:main.hex where COM7 is the port my Arduino was connected to [I got this line from the hackaday tutorial].
Both ways yielded an invalid device signature (I think it was 0x000000) error immediately. Forcing it with -F took about a minute to complete with a few different steps going from 0-100%, but verification at the end failed [I suspect it didn't connect/upload at all].
Post a photo of YOUR connections, not the ones you are trying to copy.
That last photo also states that there is no power connection between breadboard and Arduino, but you should always have a common Ground, so connect the breadboard battery negative to Arduino Gnd (or even simpler just power the breadboarded ATMega from the Arduino during programming).
Post a photo of what you have and then people can help troubleshoot. Often someone thinks they are following an example but usually the reason it doesn't work is because they have actually wired something wrong, even though they think they haven't.
tack:
Post a photo of YOUR connections, not the ones you are trying to copy.
That last photo also states that there is no power connection between breadboard and Arduino, but you should always have a common Ground, so connect the breadboard battery negative to Arduino Gnd (or even simpler just power the breadboarded ATMega from the Arduino during programming).
Post a photo of what you have and then people can help troubleshoot. Often someone thinks they are following an example but usually the reason it doesn't work is because they have actually wired something wrong, even though they think they haven't.
I will post a photo tonight. And I was using the Arduino's power (Both 5V and GND from the Arduino were connected to the power rails), and no battery.
That's good as it will be much better than trying to troubleshoot from the things you are attempting to follow.
I believe you did say that you were getting a device signature error? If so then I would look at the 328 chip and check it is actually a 328P-PU and not just a 328-PU, as they have different signatures. The ad you linked to does state it's a P-PU, but that doesn't mean that's the chip you actually received.
I just uploaded some code that someone posted for me that output a 1MHz clock to Digital pin 13 which he told me to connect to XTAL1 on the atmega, and now it works! Does this mean my chip was setup to use an external clock (though I thought fresh chips are setup to use their own 1MHz clock)? Can I set it to use its own clock?
Dblade4:
I just uploaded some code that someone posted for me that output a 1MHz clock to Digital pin 13 which he told me to connect to XTAL1 on the atmega, and now it works! Does this mean my chip was setup to use an external clock...
Yes.
(though I thought fresh chips are setup to use their own 1MHz clock)?
They are. Which means you or someone between you and the factory altered the fuses.
Can I set it to use its own clock?
Yes. With no tuning, the internal oscillator is ±10% of the frequency. With tuning you can expect ±1% (which is more than good enough for most applications).