I'm an experienced C/C++ programmer but relatively new to Arduino. I've developed a sketch on Arduino Uno and now I want to burn it into a fresh ATmega328 that will be used in my own hardware. I have found information on how to program an ATmega328 on a breadboard using the Arduino Uno as an ISP, however I have 2 questions:
I don't want the Arduino bootloader in the production system because it increases the startup time. How do I program an ATmega328 so that it starts executing my sketch immediately instead of running a bootloader? Or is there a "null bootloader" that I need to program into it?
My hardware will run with 8MHz clock instead of 16MHz. How do I build a binary image of the sketch so that the delay and timing functions are correct for an 8MHz processor?
as far as i know the arduino isp sketch won't work with arduino uno - but i may be wrong
as for the clock speed arduino uses a constant defined in boards.txt , x.build.f_cpu=16000000L where x its the name of the mcu used , that its passed to the avr-gcc compiler so you could define a new board in your boards.txt and change the build.f_cpu variable, compile the code and look inside your temp folder for the hex file or use avr-gcc as a standalone tool
for getting the sketch on the mcu there is another option on the arduino ide upload.using , so basically if you change that to one of avrdude supported programmers you could get your sketch on the mcu without the bootloader but youll need an isp programmer or you could try the optiboot bootloader which its small (i burned it on an atmega8 and took only 512bytes of space) and the delay time i think its under 2 seconds
Buy an AVRispmkII and tell the IDE to use this instead of the bootloader. If you are an experienced programmer you may want to switch to a makefile / sconstruct anyway --> makes it even easier to use an ISP.
Thanks putyn, that's very helpful. I'll try modifying boards.txt as you suggest for 8MHz. Presumably if I then recompile and upload the sketch to my Uno for testing, I should see it working at double speed. I'll then modify upload.using to load via ISP instead of the bootloader. I've read that you can run ArduinoISP on the Uno if you disable the auto-reset by connecting a 10uF capacitor between Reset and GND, so I'll try that.
Thanks to all of you for your suggestions. I've now programmed my sketch into a virgin ATmega328P in my own hardware, using the Arduino Uno as ISP. The only slightly complicated bit was setting the fuses in the processor. I've detailed the whole process at Prototyping small embedded projects with Arduino | David Crocker's Solutions blog.
dc42:
Thanks to all of you for your suggestions. I've now programmed my sketch into a virgin ATmega328P in my own hardware, using the Arduino Uno as ISP. The only slightly complicated bit was setting the fuses in the processor. I've detailed the whole process at Prototyping small embedded projects with Arduino | David Crocker's Solutions blog.
ive read the article but i have one question shouldn't the reset be connected to +5V and not to GND ?
If you're talking about the capacitor, it will disable the auto reset if you connect the capacitor between GND and Reset, or between Reset and Vcc. However, when you press the reset button, if the capacitor is connected between Reset and Vcc then it's going to put a nasty transient on Vcc. If the capacitor is connected between GND and reset, then pressing reset shorts the capacitor, which is not ideal but probably not as bad.