I have an arduino code which is working fine. Now I am planning to make a PCB out of it. But I do not want to use the complete Arduino board. I just want to use the Atmega328p
microcontroller. So my plan is to connect the USBasp programmer to the new Atmega328p and upload the code. So before this code, do I need to upload the bootloader or uploading the code first will run fine.
2 Answers
Tools > Burn Bootloader in the Arduino IDE does two things:
- Set fuses according to the settings in boards.txt for the Tools > Board selection
- Install the bootloader.
The latter is pointless since when you do an Upload Using Programmer the bootloader will be overwritten but the former is very important to do the first time you use a new chip(or anytime you want to change the fuses) to be sure that the correct fuses are set, which likely will be different from the default settings of the chip when you get it. Upload Using Programmer does not set fuses, the only way to do this via the Arduino IDE is Tools > Burn Bootloader.
So yes, you should Burn Bootloader.
-
1The act of burning the bootloader doesn't burn the fuses. They are actually a completely separate command that is executed in sequence with burning the bootloader. You do not need to burn the bootloader to set the fuses, you can do them separately. Burning the bootloader is an "easy" way of doing it, however you should really learn how to control the fuses properly if you are going to work with bare chips.– MajenkoCommented Dec 12, 2016 at 15:06
The only thing the bootloader for the ATmega328P does is to enable UART programming. If you are only using ISP then there is no need to have the bootloader.
avrdude -v -patmega328 -cusbasp -B10 -Pusb -U lfuse:w:0xA4:m -U hfuse:w:0xD1:m
(those fuse values are most likely not the correct ones). Note the-B 10
, is to slow down the USBasp programmer, as by default the ATMega328 runs at 1Mhz.