Atmel ATmega 328P

The ATmega 328P is a 8bit microcontroller from Atmel based on the AVR instruction set. It is particulary popular in the maker community as it is used as main controller in the Arduino Uno board and its various clones.

Key Info

MCU 8bit

Interfaces

UART I2C SPI

The ATmega 328P is a 8-bit AVR RISC-based microcontroller from Atmels ATmega series. Its popularity in the maker community comes from the usage in the famous Arduino Uno board and its numerous clones. The P indicates that the device supports Atmels picoPower© technology. There are two closely related parts

  • ATmega 328 without picoPower© and a few other minor differences
  • ATmega 328PB is a new device with several additions but existing code from other 328 variants compiles on the 328PB.

    • Additional SPI
    • Additional TWI
    • Additional Timer/Count
    • TC - Peripheral Touch Controller
    • CFD - Clock Failure Detection mechanism
    • USART start frame detection is available in all sleep modes
    • Analog Comparator output is available on a pin.
    • Unique device ID

See Atmels application note AT15007 for a indepth explanation.

Main features include 32 kByte ISP flash memory (read-while-write capabilities), 1 kByte EEPROM, 2 kByte SRAM, 23 general purpose I/O lines, three flexible timer/counters with compare modes, internal and external interrupts, serial programmable USART, a 2-wire I2C serial interface, SPI serial port, 6-channel 10-bit A/D converter (8-channels in TQFP and QFN/MLF packages), programmable watchdog timer with internal oscillator, and five software selectable power saving modes. Operating voltage 1.8-5V. The device achieves throughput approaching 1 MIPS per MHz.

Core AVR
Data Bus Width 8bit
Maximum Clock Frequency 20MHz
Flash Memory Size 32kB
SRAM Size 2kB
ADC Resolution 10bit
Operating Supply Voltage 1.8V to 5.5V
Operating Temperature -40C to +85C
Processor Series megaAVR
EEPROM Size 1kB
Interface Type I2C, SPI, USART
ADC Channels 6
I/Os 23/25 (depend on package)
Timers/Counters 3 Timer

Following lines show some code snippets related to ATmega 328P.

The following examples show you how to blink a LED Arduino style and Atmel Studio style Arduino Pin 9 is the same as PB1 in Atmels own syntax. Assumption is that the LED is connected on Pin 9 and obviously GND of the Ardunino board or directly o

The following


// runs after reset or powering the board
void setup() {
  // initialize digital pin 9 as an output.
  pinMode(9, OUTPUT);
}

// endless loop
void loop() {
  digitalWrite(9, HIGH);   // turn LED on (HIGH is the voltage level)
  delay(1000);               // wait a second
  digitalWrite(9, LOW);    // turn LED off by voltage LOW
  delay(1000);               // wait a second
}


// set frequency to 16MHz
#define F_CPU 16000000UL
#include <avr/io.h>
#include <util/delay.h>
int main(void)
{
  DDRB |= (1<<DDB1); //2nd bit on PORTB  to 1 means use it as output
  while(1)
  {
      PORTB |= (1<<PORTB1);    //2nd bit on PORTB on
      _delay_ms(1000);        // wait a second
      PORTB &= ~(1<<PORTB1);    //2nd bit on PORTB  off
      _delay_ms(1000);        // wait a second

CC BY-SA 2.0">

ATmega328P 28pin DIP Package
By oomlout (Flickr: ATMEGA328 - IC-ATM328-01) CC BY-SA 2.0