![]() ![]() ![]() ![]() ![]() Alan numitron clock Clapclap 2313/1386 SNES Pi Webserver USB Volume/USB toys Smokey amp Laser cutter WordClock ardReveil v3 SNES Arcade cabinet Game boy projects cameleon Home Presence Detector ![]() AlanFromJapan ![]() ![]() ![]() Akizukidenshi Elec-lab Rand Nerd Tut EEVblog SpritesMods AvrFreaks Gameboy Dev FLOZz' blog Switch-science Sparkfun Suzusho Datasheet Lib Reddit Elec Ermicro Carnet du maker (fr) |
ATmega328Last update: Thu Jun 5 22:25:40 2025
![]() ATmega 328... or simply using only ATmel µC and let the Arduino what it's made for : a wonderful prototyping tool.Memo fact sheet
ATmega328p is the core of an Arduino. You can build any Arduino compatible board by yourself, for cheap if you discard the Serial-over-USB IC. Receipe (bare minimum):
Afterward, code can be uploaded via a programmer (Pololu AVR Programmer for me) by soldering a nice 6pins connector OR by putting the chip onto an Arduino board. Just remove carefully the original Arduino chip and put it somewhere else. Put the blank chip in the correct place, connect the ISP programmer and upload a bootloader. #!/bin/bash avrdude -c avrispv2 -p m328p -D -P /dev/ttyACM0 -U flash:w:ATmegaBOOT_168_atmega328.hexThen, you can upload code using Arduino IDE, or you could just directly burn the image you created (search the .hex file). You now have a chip that can run code exactly as is doing your Arduino for something like 1/3rd of the price. Note that I'm talking of the minimal version, excluding the Serial-over-USB, and that of course you will spend time soldering. That's a tradeoff, so up to you. But Arduino is not a end in itself, it's a wonderful prototyping tool; unless you want a perpetual USB connection and don't bother with USB power, Arduino is an overkill. Spend 2 hours preparing your Home-made-Arduino, you'll learn a lot. You can make a "in place" programmer that you put over your cpu. I loooove the design, I have to make one (I always found that soldering that 6pin connector was a waste of time).
Pins and legs of an ATmega328![]() ![]() On this schema, you can see the chip with its legs (outer figures with no color) and how it is mapped to Arduino's pins. The 3 groups of pins are displayed with colors :
How to get 2 extra pins ?Simple but you have to think of it : if you don't need precise clock nor speed > 8MHz, just use the internal oscillator and recycle the two crystal pins ! They are PB6 and PB7 and are just waiting for you ! How simple ... (source )FusesSetting up the fuse is necessary (and potentially risky) to tell the uC to use a 16MHz crystal with slow startup (?), which speed, make read-only, ... It's not black magic, just be a little careful. There is a wondeful site for preparing the command line for you : http://www.engbedded.com/fusecalc/The standard fuses for Arduino "Genuino"avrdude -c avrispmkII -p m328p -P usb -U hfuse:w:0xDE:m -U lfuse:w:0xFF:m -U efuse:w:0x05:mPS: I read for the HIGH fuse alternate 0xDA or 0xD6 ... there's a good article on Sparkfun, well worth reading (also explains how to put the official bootloarder on a virgin ATmega). Power consumptionVeeeeery low, like 1 mA when turned on (? to be confirmed).Here's a link on how to make the power consumption go ultra low : http://news.jeelabs.org/2009/05/16/power-consumption-more-savings/ USB connectionMisc links:
I2C
InterruptsTimers
WatchdogExternal interrupt and Pin Change interrupt
Power considerations
$h!t I #&$!ed my Atmega's fusesThat happens to EVERYONE ... and to some more than to others.
PWM
Samples project
Interruptsvoid setup() { D2 is input DDRD &= ~(1 << 2); pullup on D2 PORTD |= (1 << 2); interrupt on falling hedge of INT0 EICRA |= (1 << ISC01); INT0 enabled EIMSK |= (1 << INT0); Go interrupts !! sei(); pinMode(13, OUTPUT); } void loop() { put your main code here, to run repeatedly: } volatile int ledState = LOW; ISR (INT0_vect) { if the LED is off turn it on and vice-versa: if (ledState == LOW) ledState = HIGH; else ledState = LOW; set the LED with the ledState of the variable: digitalWrite(13, ledState); } |
All content on this site is shared under the MIT licence (do what u want, don't sue me, hat tip appreciated) electrogeek.tokyo ~ Formerly known as Kalshagar.wikispaces.com and electrogeek.cc (AlanFromJapan [2009 - 2025]) |