ATmega328P 2018-12-20 Atmega328 is a popular microcontroller from the AVR family, it's cheap and useful - just the way we like it. It is commonly found in arduinos. Having one you can make an arduino yourself. The foundation of an arduino is it's bootloader. So... the first step to make your very own arduino is to properly plug the atmega chip and flash it with an arduino bootloader. And that's exactly what I did just a moment ago! Let me explain HOW. As always in electronics, look up the datasheet. There you can find your chip's pinout. Plug GND to GNDs and 5V in into VCC (and AVCC, and AREF) normally and to RESET through a 10k Ohm resistor. If you have a crystal plug it between the XTAL pins and then to GND through 22 pF caps. More datails here: https://www.arduino.cc/en/Main/Standalone To program the chip you will need 6 pins. We already have VCC, GND and RESET. 3 more to go: SCK, MOSI and MISO. I'm still a newbie in electronics, so I can't really explain to you what all this means and does, but basically we need those pins plugged into corresponding pins on our programmer. The easiest way is to use a different arduino, but you could also try it with RaspberryPi GPIO (comming up next! there are multiple tutorials online) or buy a dedicated programmer. I settled for the easiest way, nearly every arduino board has 6 male ICSP pins just perfect for our purpose. And there's an example sketch available in the arduino IDE - ArduinoISP. It's well documented, I suggest you read through all the comments in that code. It could have saved me a lot of time. *from the ArduinoISP sketch*
// Pin 10 is used to reset the target microcontroller.
//
// By default, the hardware SPI pins MISO, MOSI and SCK are used to communicate
// with the target. On all Arduinos, these pins can be found
// on the ICSP/SPI header:
//
//               MISO °. . 5V (!) Avoid this pin on Due, Zero...
//               SCK   . . MOSI
//                     . . GND
Just connect those with corresponding pins on your AVR and you're ready to go. Theoretically it's enough to compile and upload that sketch onto your working arduino, then select proper target (for example "Arduino Nano" board with "ATmega328P" processor) and then use the "Burn Bootloader" option from the IDE. Like in here: https://www.arduino.cc/en/Tutorial/ArduinoISP But that did not work for me... I switched on verbose output in arduino IDE's preferences and after quite some time of fruitless work I asked for help on IRC (#avrs @freenode). <wykwit> I'm always getting the Device signature = 0x000000 with atmega328p <wykwit> what could I be doing wrong? ... <polprog> make sure the connections are ok ... <Emil> wykwit: you need 6 pins for spi programming <Emil> vcc, gnd, rst, sck, mosi, miso <Emil> Depending on the burned fuses, you might need a crystal of appropriate frequency on the xtal pins <Emil> you also might need to use the low speed programming if first if you have the div/8 fuse burned (by default it is) <wykwit> lowering the SPI_CLOCK in ArduinoISP script worked just fine <wykwit> thanks ... <polprog> wykwit: yeah thats a good trick. works 9 outta ten times ;) You should REALLY CAREFULLY read the comments in the sketch and adjust values accordingly, so everything works fine for you. Pay attention especially to SPI_CLOCK and BAUDRATE settings. I suppose the first flash could work with the default SPI_CLOCK and BAUDRATE of 1000000 (3rd option). Try it out. I finally flashed with SPI_CLOCK set to (1000000/32) and a default BAUDRATE of 19200. You could probably get those magic values from the datasheet, but the datasheet is more than 600 pages long, so I just dug some values up from the internets and experimented. For those who are curious about The Real toolchain and how all of this works under the hood I highly suggest reading documentation at: http://www.nongnu.org/avr-libc/ Now I'll have to look into fuses. They're important, but we automatically set them when flashing arduino bootloader. If you want to keep hacking your ATmega328 with the arduino IDE this chart might be helpfull: https://www.arduino.cc/en/Hacking/PinMapping168 Now you can simply keep uploading new sketches through your current arduino setup with the "Upload Using Programmer" option.