Разобрался, как прошивать голую микросхему микроконтроллера atmega328p-pu, который лежит в основе плат Arduino. Источников информации много, но пришлось разобраться во всех, потому что ни на одном из них работающую процедуру под мой случай найти не удалось. На случай, если вдруг кому-нибудь еще такое понадобится, выложу сюда, на английском.
Learned recently how to program the bare atmega328p-pu microcontroller. The sources of information I used were plenty, but unfortunately, none of the approaches worked from the scratch, I had to compile information and think over some of it, so I'm putting here the whole process that worked for me. I'll try to be short and clear.
Input: I have Arduino Nano V.3 clone, a bare atmega328p-pu chip, a recent Arduino 1.6.0 software and nothing else. Objective: write, debug and test sketches on Nano, and upload them after to the atmega328p-pu chip for production.
1. Following the 'Minimal Circuit' section of this
tutorial and keeping in mind we have Arduino Nano, and not the board shown there on the picture, we connect the following:
* pin d13 on Nano - to pin 19 on the chip
* pin d12 on Nano - to pin 18 on the chip
* pin d11 on Nano - to pin 17 on the chip
* pin d10 on Nano - to pin 1 on the chip
* power rails on both breadboards, if you use different for Nano and the chip
* pin 7 (vcc) on the chip - to (+)
* pin 8 (ground) on the chip - to (-)
* pin 21 (aref) on the chip - to (+)
* pin 22 (ground) on the chip - to (-)
* (optional) insert LED (with resistor) between pin 13 (pd7) on the chip and the ground to see the sketch we are going to upload working
* (optional) insert LED (with resistor) between pin 19 (pb5) on the chip and the ground to watch the upload process
* (optional) insert LEDs (with resistors) between pins d7, d8, d9 on Nano and the ground to watch the Nano programming mechanisms working
This is how it all looks in my case:
2. Open the 'ArduinoISP' sketch from File -> Examples -> ArduinoISP, connect your Nano to the USB port, then assure you have Tools -> Board -> Arduino Nano selected, Tools -> Programer -> AVRISP mkII and upload the ArduinoISP sketch to your Nano, turning it into a real programmer, which will in turn program you barebone atmega328p-pu chip. You'll see the LED on D9 of Nano slowly beating, as the sketch signals it is ready to program any chip necessary.
3. As the
tutorial suggests, download the
hardware configuration archive, locate your sketches folder on the disks (mine in Windows 7 was in C:\Users\myusername\Documents\Arduino), create the subfolder 'hardware' and extract the contents of the archive (the 'breadboard' folder and everything inside) into it.
4. IMPORTANT! Edit the 'hardware\breadboard\avr\boards.txt' file you have just unpacked, and insert two following lines in the appropriate places inside:
atmega328bb.upload.tool=arduino:avrdude
atmega328bb.bootloader.tool=arduino:avrdude
5. IMPORTANT! Download the
ATmegaBOOT_168_atmega328_pro_8MHz.hex file and put it into 'hardware\breadboard\avr\bootloaders' folder.
6. Restart the Arduino software and ensure you have selected "ATmega328 on a breadboard (8 MHz internal clock)" in the Tools -> Board menu, and "Arduino as ISP" in Tools -> Programmer menu.
7. Run Tools -> Burn Bootloader. If you have missed step 4, you get an error "Error while burning bootloader: missing 'bootloader.tool' configuration parameter". If you have missed step 5, you get an error about missing ATmegaBOOT_168_atmega328_pro_8MHz.hex file. If you're lucky enough, the bootloader will be uploaded successfully. It should be done only once and is not really that necessary. I was able to upload the first sketch to the newly bought atmega328p-pu chip BEFORE uploading the bootloader, but it behaved strangely.
8. Create a simple sketch in Arduino software:
void setup() {
pinMode(7, OUTPUT);
}
void loop() {
digitalWrite(7, HIGH);
delay(1000);
digitalWrite(7, LOW);
delay(1000);
}
Note we have used pin 7, as the sketch will be uploaded into the atmega328p-pu chip, where we have prepared a LED on pin 13 (pd7).
9. Select File -> "Upload using the programmer" menu, and both the LED on pin 7 of Nano, and LED on pin 19 of the chip will flicker as the data will be transfered to the chip. Immediately after, the LED on pin 13 (pd7) of the chip will start to blink every second, showing that the sketch was delivered into the chip. Hurray!
10. The sources of information:
ArduinoBoardNanoArduinoNano30Schematic.pdfArduinoToBreadboardArduinoISParduino-nano-as-an-isp-programmerArduino-Hardware-Cores-migration-guide-from-1.0-to-1.6ATMEGA328P-PU datasheet