ATmega328P Block Diagram Explained: Architecture, Pin Diagram and Assembly Instructions

The ATmega328P is an 8-bit AVR microcontroller widely used in embedded systems, electronics projects, and Arduino-based applications. It is the main microcontroller used on the popular Arduino Uno board. It combines a CPU, program memory, data memory, input/output ports, timers, communication interfaces, and analog peripherals in a single chip. Understanding the ATmega328P block diagram helps students learn how these internal components communicate and work together. It is also an important topic for ECE and EEE students studying microcontrollers, embedded C programming, and embedded system design. In this article, we will explore the ATmega328P internal block diagram, its architecture, memory organization, pin diagram, peripheral functions, working principle, and commonly used ATmega328P assembly instructions.

ATmega328P Block Diagram, Architecture & Pin Diagram

What Is ATmega328P?

ATmega328P is an 8-bit microcontroller developed by Atmel, now part of Microchip Technology. It is based on the AVR enhanced RISC architecture and uses a Harvard architecture, which separates program memory and data memory.

The microcontroller can execute instructions, process sensor inputs, control electronic devices and communicate with external components through its built-in peripherals.

Important Specifications of ATmega328P

SpecificationDetails
Microcontroller familyAVR
Architecture8-bit RISC
Operating voltage1.8V–5.5V
Maximum CPU clock frequency20 MHz
Flash memory32 KB
SRAM2 KB
EEPROM1 KB
General-purpose I/O23 programmable lines
Timers/CountersTwo 8-bit and one 16-bit
ADC10-bit
Communication interfacesUSART, SPI, TWI (I2C-compatible)
Watchdog timerYes
Package options28-pin and 32-pin variants

These specifications make ATmega328P suitable for small embedded applications that require processing, timing, analog measurement and communication capabilities.

ATmega328P Block Diagram

 ATmega328P Block Diagram-iies

The ATmega328P block diagram represents the internal functional units of the microcontroller and explains how they are connected through internal buses.

The major blocks include:

  • AVR CPU
  • Flash program memory
  • SRAM
  • EEPROM
  • General-purpose registers
  • Arithmetic Logic Unit (ALU)
  • Input/output ports
  • Timer and counter units
  • Analog-to-Digital Converter (ADC)
  • USART communication interface
  • SPI interface
  • TWI interface
  • Interrupt controller
  • Clock and reset circuits
  • Watchdog timer

The diagram can be understood by dividing the microcontroller into five main sections: processing unit, memory, input/output, communication peripherals, and timing and control circuits.

Explanation of Each Block in the ATmega328P Internal Block Diagram

AVR CPU

The CPU is the central processing unit of the ATmega328P. It controls the execution of instructions stored in program memory and manages communication between the memory and peripheral devices.

The AVR CPU contains:

  • Arithmetic Logic Unit (ALU)
  • 32 general-purpose working registers
  • Program Counter (PC)
  • Stack Pointer (SP)
  • Status Register (SREG)
  • Instruction Register
  • Instruction Decoder

The CPU fetches instructions, decodes them and executes the required operations.

For example, when a program reads a sensor value and compares it with a predefined threshold, the CPU performs the necessary operations and controls the output accordingly.

Flash Program Memory

Flash memory stores the program or instructions that the microcontroller executes.

ATmega328P contains 32 KB of in-system programmable Flash memory. It is non-volatile, which means the stored program remains available even when the power supply is disconnected.

The microcontroller retrieves instructions from Flash memory during program execution.

For example, an Arduino program uploaded to an Arduino Uno is stored in the ATmega328P’s Flash memory.

SRAM (Static Random Access Memory)

SRAM is the temporary working memory of the microcontroller. It stores variables, temporary data and the stack while a program is running.

ATmega328P contains 2 KB of SRAM. Unlike Flash memory, SRAM is volatile. Its contents are lost when the power supply is turned off.

For example, when a program reads a temperature sensor value, the measured value can be temporarily stored in SRAM for further processing.

EEPROM (Electrically Erasable Programmable Read-Only Memory)

EEPROM is non-volatile memory used to store data that must remain available even after the microcontroller is powered off.

ATmega328P contains 1 KB of EEPROM. It is useful for storing:

  • Device configuration settings
  • Calibration values
  • User preferences
  • Counters and selected application data

For example, an electronic device can store its last selected operating mode in EEPROM and retrieve it after restarting.

Arithmetic Logic Unit (ALU)

The ALU performs arithmetic and logical operations required by the CPU.

Its operations include:

  • Addition
  • Subtraction
  • Comparison
  • Logical AND
  • Logical OR
  • Exclusive OR
  • Increment and decrement

The ALU works with the general-purpose registers to process data.

For example, if a program needs to compare two sensor readings, the ALU performs the required comparison operation and updates the status flags.

General-Purpose Registers

ATmega328P has 32 general-purpose 8-bit working registers, named R0 to R31. These registers are directly connected to the ALU and are used to store operands and intermediate results during program execution.

For example, an assembly instruction can load a constant into a register:

LDI R16, 25

This instruction loads the value 25 into register R16. The general-purpose registers help the CPU perform operations efficiently without repeatedly accessing SRAM.

Input/Output Ports

The ATmega328P provides 23 programmable general-purpose I/O lines divided into three ports:

  • PORTB
  • PORTC
  • PORTD

These ports allow the microcontroller to interact with external electronic components. They can be configured as inputs or outputs depending on application requirements.

Examples include:

  • Reading push-button inputs
  • Controlling LEDs
  • Driving relays through suitable driver circuits
  • Interfacing with sensors
  • Generating digital control signals

Each port has associated registers for controlling its direction, output value and input reading.

Timer and Counter Units

Timers and counters are used to measure time intervals, generate delays, count external events and produce PWM signals.

ATmega328P contains three timer/counter units:

TimerResolutionCommon Applications
Timer 08-bitTiming and PWM generation
Timer 116-bitAccurate timing, input capture and PWM
Timer 28-bitTiming and PWM generation

Timers can operate using the internal clock or supported external clock sources.

For example, a timer can generate a periodic interrupt to perform an operation at regular intervals without continuously checking the time in the main program.

Analog-to-Digital Converter (ADC)

The ADC converts analog input signals into digital values that the CPU can process.

ATmega328P has a 10-bit ADC. In the common 28-pin DIP package, it provides six ADC input channels. The 32-pin TQFP and QFN/MLF packages provide eight ADC channels. A 10-bit ADC produces digital values from 0 to 1023.

For example, a temperature sensor may produce an analog voltage. The ADC converts that voltage into a digital value, which the CPU can use to calculate or display the temperature.

USART Communication Interface

USART stands for Universal Synchronous and Asynchronous Serial Receiver and Transmitter. It enables serial communication between the ATmega328P and external devices.

Common applications include:

  • Communication with a computer
  • Serial debugging
  • GPS module interfacing
  • Communication with other microcontrollers

The USART uses the RXD and TXD pins for receiving and transmitting data in asynchronous mode.

SPI Interface

SPI stands for Serial Peripheral Interface. It is a synchronous serial communication protocol used to exchange data between a microcontroller and peripheral devices.

The main SPI signals are:

  • MOSI – Master Out, Slave In
  • MISO – Master In, Slave Out
  • SCK – Serial Clock
  • SS – Slave Select

SPI is commonly used to interface with memory devices, displays, sensors and other SPI-compatible peripherals.

TWI Interface

TWI stands for Two-Wire Interface. It is compatible with the I2C communication protocol.

It uses two main signal lines:

  • SDA – Serial Data
  • SCL – Serial Clock

TWI allows the microcontroller to communicate with multiple compatible devices using a shared two-wire bus.

For example, an ATmega328P can communicate with an I2C-based LCD module or sensor using the SDA and SCL lines.

Interrupt Unit

An interrupt is a signal that temporarily changes the normal program execution flow so that the CPU can respond to an event. ATmega328P supports external and internal interrupt sources.

Examples include:

  • External interrupt from a push button
  • Timer overflow interrupt
  • ADC conversion complete interrupt
  • USART data reception interrupt

When an enabled interrupt occurs, the CPU executes the corresponding Interrupt Service Routine (ISR) and then returns to the previous program flow.

Interrupts are useful when an application must respond quickly to an event without continuously polling the device.

Watchdog Timer

The watchdog timer is a safety mechanism that helps recover from certain software failures.

The program periodically resets the watchdog timer. If the program becomes stuck and fails to reset it within the configured time, the watchdog can generate a system reset.

This feature is useful in embedded products that need reliable operation with minimal human intervention.

Clock and Reset Circuit

The clock circuit provides the timing reference required for CPU and peripheral operation. ATmega328P supports internal clock sources and external clock arrangements, depending on configuration.

The RESET pin is used to restart the microcontroller. The reset circuitry initializes the device and begins program execution from the reset vector.

The clock and reset circuits are essential for correct and controlled microcontroller operation.

ATmega328P Architecture Diagram and Working Principle

ATmega328P Architecture Diagram_iies

The ATmega328P microcontroller architecture is based on an 8-bit AVR RISC processor and follows the Harvard architecture.

In Harvard architecture, program memory and data memory are separated. This allows the CPU to fetch instructions from Flash memory while accessing data through the data memory system.

The AVR architecture also uses instruction pipelining. While one instruction is being executed, the next instruction can be fetched. This helps improve instruction throughput.

How Does ATmega328P Work?

The basic working process can be understood through the following steps:

  • Power supply: The microcontroller receives the required operating voltage.
  • Clock generation: The clock circuit provides timing signals for the CPU and peripherals.
  • Program fetching: The CPU fetches instructions from Flash program memory.
  • Instruction decoding: The instruction decoder identifies the operation to be performed.
  • Instruction execution: The ALU and registers perform the required arithmetic or logical operation.
  • Data handling: The CPU reads or writes data using SRAM, EEPROM and peripheral registers.
  • Input/output operation: The microcontroller reads inputs or controls external devices through its I/O ports.
  • Interrupt handling: When an enabled interrupt occurs, the CPU executes the corresponding interrupt service routine.

Example: LED Control Using ATmega328P

Consider a simple application in which an LED is connected to digital pin PB5. The microcontroller can perform the following operations:

  • Configure PB5 as an output.
  • Set PB5 HIGH to turn on the LED.
  • Set PB5 LOW to turn off the LED.
  • Repeat the process according to the required timing.

This example demonstrates how the CPU, Flash memory, I/O ports, clock circuit and program instructions work together in a practical embedded application.

ATmega328P Pin Diagram

atmega328p_pin_diagram_iies

The ATmega328P pin diagram shows the physical pins available for power, ground, clock, reset, analog inputs, digital inputs and outputs, and communication interfaces.

The microcontroller is available in different package options. The following pin details refer to the commonly used 28-pin DIP package.

ATmega328P Pin Configuration

Pin NumberPin NameFunction
1PC6 / RESETReset input
2PD0 / RXDUSART receive
3PD1 / TXDUSART transmit
4PD2 / INT0External interrupt 0
5PD3 / INT1External interrupt 1, PWM
6PD4Digital I/O
7VCCDigital power supply
8GNDGround
9PB6 / XTAL1Crystal oscillator input
10PB7 / XTAL2Crystal oscillator output
11PD5Digital I/O, PWM
12PD6Digital I/O, PWM
13PD7Digital I/O
14PB0Digital I/O
15PB1Digital I/O, PWM
16PB2 / SSSPI slave select
17PB3 / MOSISPI data output
18PB4 / MISOSPI data input
19PB5 / SCKSPI clock
20AVCCAnalog supply voltage
21AREFADC reference input
22GNDGround
23PC0 / ADC0Analog input 0
24PC1 / ADC1Analog input 1
25PC2 / ADC2Analog input 2
26PC3 / ADC3Analog input 3
27PC4 / ADC4 / SDAAnalog input 4, TWI data
28PC5 / ADC5 / SCLAnalog input 5, TWI clock

Important: The 32-pin TQFP and QFN/MLF package versions include additional ADC6 and ADC7 inputs. These are not available as general-purpose digital I/O pins. Always check the pinout for the exact package before designing a circuit.

Important ATmega328P Pin Groups

  • Power supply pins: VCC and GND provide the digital power supply connections. AVCC supplies the analog section and should be connected appropriately even when the ADC is not being used.
  • Clock pins: XTAL1 and XTAL2 are used with an external crystal or resonator when an external clock arrangement is selected.
  • Reset pin: The RESET pin restarts the microcontroller and is commonly connected to a reset circuit.
  • Digital I/O pins: PORTB, PORTC and PORTD provide programmable digital input and output functions.
  • Analog input pins: ADC0 to ADC5 are available in the 28-pin DIP package for measuring analog signals.
  • Communication pins: RXD and TXD support USART communication. MOSI, MISO and SCK support SPI. SDA and SCL support TWI communication.

ATmega328P Memory Organization

Memory organization is an important part of ATmega328P microcontroller architecture. The microcontroller uses three main types of memory.

Memory TypeCapacityPurpose
Flash32 KBStores program instructions
SRAM2 KBStores temporary variables and runtime data
EEPROM1 KBStores non-volatile application data

Flash Memory

Flash memory stores the application program. It is non-volatile and can be programmed through supported programming methods.

SRAM

SRAM is used during program execution. It stores variables, temporary data and the stack.

EEPROM

EEPROM is useful when data must be retained even after power is removed. It is commonly used for configuration values and calibration information.

Understanding the difference between these three memory types is important when writing embedded C programs and designing memory-efficient applications.

ATmega328P Assembly Instructions

ATmega328P uses the AVR instruction set, which contains instructions for data transfer, arithmetic, logical operations, branching and bit manipulation.

Assembly language allows programmers to control the microcontroller at a lower level compared with high-level languages such as C. The following are commonly used ATmega328P assembly instructions.

Data Transfer Instructions

These instructions move data between registers, memory and I/O locations.

InstructionFunction
MOVCopies data from one register to another
LDILoads an immediate value into a register
LDSLoads data directly from data memory
STSStores data directly into data memory
LDLoads data indirectly using a pointer register
STStores data indirectly using a pointer register
PUSHPushes a register value onto the stack
POPRetrieves a value from the stack

Example: LDI R16, 10 — this instruction loads the value 10 into register R16.

Arithmetic Instructions

Arithmetic instructions perform mathematical operations.

InstructionFunction
ADDAddition
ADCAddition with carry
SUBSubtraction
SBCSubtraction with carry
INCIncrement by one
DECDecrement by one
MULMultiplication
NEGTwo’s complement negation

Example: ADD R16, R17 — this instruction adds the contents of R17 to R16 and stores the result in R16.

Logical Instructions

Logical instructions perform bitwise operations on register data.

InstructionFunction
ANDBitwise AND
ORBitwise OR
EORExclusive OR
COMOne’s complement
CLRClears a register
TSTTests a register
LSLLogical shift left
LSRLogical shift right

Example: AND R16, R17 — this instruction performs a bitwise AND operation between R16 and R17.

Branch and Control Instructions

These instructions change the normal program execution sequence.

InstructionFunction
RJMPRelative jump
JMPAbsolute jump
RCALLRelative subroutine call
CALLAbsolute subroutine call
RETReturns from a subroutine
RETIReturns from an interrupt routine
BRNEBranch if not equal
BREQBranch if equal

Example: RJMP LOOP — this instruction transfers program execution to the label LOOP.

Bit Manipulation Instructions

Bit manipulation is important when controlling individual hardware pins and peripheral registers.

InstructionFunction
SBISets a bit in an I/O register
CBIClears a bit in an I/O register
SBISSkips the next instruction if a bit is set
SBICSkips the next instruction if a bit is clear
BSTStores a bit in the T flag
BLDLoads a bit from the T flag

Example: SBI PORTB, 5 — this instruction sets bit 5 of PORTB, making PB5 HIGH when configured as an output.

Simple Assembly Example: Configuring an LED Output

The following AVR assembly example configures PB5 as an output and turns it ON.

LDI R16, 0x20
OUT DDRB, R16

SBI PORTB, 5

LOOP:
RJMP LOOP

Explanation:

  • LDI R16, 0x20 loads the bit pattern for bit 5 into R16.
  • OUT DDRB, R16 configures PB5 as an output.
  • SBI PORTB, 5 sets PB5 HIGH.
  • RJMP LOOP keeps the program running in a continuous loop.

A suitable current-limiting resistor must be connected in series with the LED. The example demonstrates basic AVR register control; it does not include a blinking delay.

Applications of ATmega328P

ATmega328P is used in several educational, prototyping and embedded control applications.

Some common applications include:

  • Arduino-based projects: Used in Arduino Uno boards for learning programming and building prototypes.
  • Sensor monitoring systems: Reads analog and digital sensor signals and processes the measured data.
  • Home automation: Controls lights, relays and other devices through suitable driver circuits.
  • Temperature monitoring: Reads temperature sensor outputs using its ADC.
  • Robotics: Controls motors and reads inputs from sensors through suitable interface circuits.
  • Digital measuring instruments: Supports measurement and display applications.
  • Data logging: Collects sensor data and stores selected information using external or internal memory resources.

Advantages of ATmega328P

  • Simple 8-bit AVR architecture for learning microcontroller fundamentals
  • Built-in Flash, SRAM and EEPROM
  • Multiple programmable I/O pins
  • Integrated ADC for analog signal measurement
  • Timers and PWM support
  • USART, SPI and TWI communication interfaces
  • Low-power operating modes
  • Widely used Arduino development ecosystem and learning resources

Conclusion

The ATmega328P block diagram provides a clear understanding of how the CPU, memory, I/O ports, timers, ADC, communication interfaces and control circuits work together inside an 8-bit microcontroller.

Learning its internal architecture, pin configuration, memory organization and assembly instructions gives students a strong foundation in microcontroller programming and embedded system development.

For students who want to move beyond theoretical concepts, practical experience with microcontrollers, embedded C, peripheral interfacing and real-time hardware projects is essential. At the Indian Institute of Embedded Systems (IIES), Bangalore, students can develop these skills through practical embedded systems training and hands-on microcontroller projects.

Explore the Embedded Systems Course with Placement to build a strong foundation in microcontrollers, Embedded C and real-time project development.

Talk to Academic Advisor

Frequently Asked Questions

ATmega328P is an 8-bit AVR RISC-based microcontroller that uses Harvard architecture, with separate program and data memory spaces.

ATmega328P has 32 KB of Flash program memory.

It has 2 KB of SRAM and 1 KB of EEPROM.

ATmega328P provides 23 programmable general-purpose I/O lines across PORTB, PORTC, and PORTD.

The ADC has a 10-bit resolution and produces values from 0 to 1023.

Author

Embedded Systems and IOT Trainer– IIES

Updated On: 28-11-26


10+ years of hands-on experience delivering practical training in Embedded Systems and it's design