Learn, Implement and Share

Note

This article is a part of Arduino / ATmega328p Embedded C Firmware Programming Tutorial. Consider exploring the course home page for articles on similar topics.

Arduino Tutorial Embedded C Register Level Arduino Master Class

Arduino Tutorial Embedded C Register Level Arduino Master Class

Also visit the Release Page for Register Level Embedded C Hardware Abstraction Library and Code for AVR.

Introduction

This section discusses the Atmega328p and Arduino Pinout and Mapping. The Arduino style pinout is mapped with the chip style pinout and the alternate functions are described.

Most port pins have alternate functions in addition to being general digital I/Os. The below article shows and discusses the peripheral available in each port pin and their alternate functions.

What You Will Learn

  • What are the different pins in Arduino UNO?
  • What are the pin configuration of AVR ATmega328p chip?
  • How many ports are there in ATmega328p?
  • What are the alternate function of each Arduino pin?

ATmega328P Pin Configuration / PinOut

Below are the two most popular packages of ATmega328P that are sold and used in Arduino Board. Arduino UNO uses the PDIP package of ATmega328P and Arduino NANO uses the TQFP Package of ATmega328P.

Atmega328p DIP Dual Inline Package Pin Out
Atmega328p DIP (Dual Inline Package) Pin Out
Arduino Pin Mapping with Atmega328p
Arduino UNO Pin Mapping with Atmega328p
Atmega328p TQFP Thin Quad Flat Package Pin Out
Atmega328p TQFP (Thin Quad Flat Package) Pin Out
Arduino NANO Pin Mapping with ATmega328P
Arduino NANO Pin Mapping with ATmega328P

Pin Description ATmega328P

VCC

Digital Supply Voltage for the operation of the chip.

GND

Digital Supply Ground for the operation of the chip.

AVCC

AVCC is the supply voltage pin for the A/D Converter, PC3:0, and ADC7:6. It should be externally connected to VCC, even if the ADC is not used. If the ADC is used, it should be connected to VCC through a low-pass filter. Note that PC6…4 use digital supply voltage, VCC.

AREF

AREF is the analog reference pin for the A/D Converter.

ADC7:6 (TQFP and QFN/MLF Package Only) (D21:D20 Arduino NANO)

In the TQFP and QFN/MLF package, ADC7:6 serves as analog inputs to the A/D converter. These pins are powered from the analog supply and serve as 10-bit ADC channels.

Port B (PB7:0)

Port B is an 8-bit bi-directional I/O port with internal pull-up resistors (selected for each bit). The Port B output buffers have symmetrical drive characteristics with both high sink and source capability. As inputs, Port B pins that are externally pulled low will source current if the pull-up resistors are activated. The Port B pins are tri-stated when a reset condition becomes active, even if the clock is not running.

Depending on the clock selection fuse settings, PB6 can be used as input to the inverting Oscillator amplifier and input to the internal clock operating circuit.

Depending on the clock selection fuse settings, PB7 can be used as output from the inverting Oscillator amplifier.

If the Internal Calibrated RC Oscillator is used as the chip clock source, PB7…6 is used as TOSC2…1 input for the Asynchronous Timer/Counter2 if the AS2 bit in ASSR is set.

Port PinArduino PinAlternate Functions
PB7XTAL2 (Chip Clock Oscillator pin 2)
Used as clock pin for Crystal Oscillator or Low-frequency Crystal Oscillator.
When used as a clock pin, the pin can not be used as an I/O pin.
TOSC2 (Timer Oscillator pin 2)
In this mode, a crystal Oscillator is connected to this pin and used for asynchronous clocking of Timer/Counter2 and the pin cannot be used as an I/O pin.
PCINT7 (Pin Change Interrupt 7)
The PB7 pin can serve as an external interrupt source.
PB6XTAL1 (Chip Clock Oscillator pin 1 or External clock input)
Used for all chip clock sources except internal calibrated RC Oscillator. When used as a clock pin, the pin can not be used as an I/O pin.
TOSC1 (Timer Oscillator pin 1)

In this mode, a crystal Oscillator is connected to this pin and used for asynchronous clocking of Timer/Counter1 and the pin cannot be used as an I/O pin.
PCINT6 (Pin Change Interrupt 6)

The PB6 pin can serve as an external interrupt source.
PB5D13SCK (SPI Bus Master clock Input)
When the SPI is enabled as a Slave, this pin is configured as an input regardless of the setting of DDB5. When the SPI is enabled as a Master, the data direction of this pin is controlled by DDB5.
PCINT5 (Pin Change Interrupt 5)

The PB5 pin can serve as an external interrupt source.
PB4D12MISO (SPI Bus Master Input/Slave Output)
When the SPI is enabled as a Master, this pin is configured as an input regardless of the setting of DDB4. When the SPI is enabled as a Slave, the data direction of this pin is controlled by DDB4.
PCINT4 (Pin Change Interrupt 4)

The PB4 pin can serve as an external interrupt source.
PB3D11MOSI (SPI Bus Master Output/Slave Input)
When the SPI is enabled as a Slave, this pin is configured as an input regardless of the setting of DDB3. When the SPI is enabled as a Master, the data direction of this pin is controlled by DDB3.
OC2A (Timer/Counter2 Output Compare Match A Output)

This pin can serve as an external output for the Timer/Counter2 in Compare Match mode or PWM mode.
PCINT3 (Pin Change Interrupt 3)

The PB3 pin can serve as an external interrupt source.
PB2D10SS (SPI Bus Master Slave select)
When the SPI is enabled as a Slave, this pin is configured as an input regardless of the setting of DDB2. When the SPI is enabled as a Master, the data direction of this pin is controlled by DDB2.
OC1B (Timer/Counter1 Output Compare Match B Output)

This pin can serve as an external output for the Timer/Counter1 in Compare Match mode or PWM mode.
PCINT2 (Pin Change Interrupt 2)

The PB2 pin can serve as an external interrupt source.
PB1D9OC1A (Timer/Counter1 Output Compare Match A Output)
This pin can serve as an external output for the Timer/Counter1 in Compare Match mode or PWM mode.
PCINT1 (Pin Change Interrupt 1)

The PB1 pin can serve as an external interrupt source.
PB0D8ICP1 (Timer/Counter1 Input Capture Input)
The PB0 pin can act as an Input Capture Pin for Timer/Counter1.
CLKO (Divided System Clock Output)

The divided system clock can be output on the PB0 pin. It will also be output during reset.
PCINT0 (Pin Change Interrupt 0)

The PB0 pin can serve as an external interrupt source.
Port PinArduino PinAlternate Function

Port C (PC5:0)

Port C is a 7-bit bi-directional I/O port with internal pull-up resistors (selected for each bit). The PC5…0 output buffers have symmetrical drive characteristics with both high sink and source capability. As inputs, Port C pins that are externally pulled low will source current if the pull-up resistors are activated. The Port C pins are tri-stated when a reset condition becomes active, even if the clock is not running.

Port PinArduino PinAlternate Function
PC6RESETRESET (Reset pin)
When the RSTDISBL Fuse is programmed, this pin functions as a normal I/O pin, and ATmega328P will have to rely on Power-on Reset and Brown-out Reset as its reset sources. When the RSTDISBL Fuse is unprogrammed, the reset circuitry is connected to the pin, and the pin can not be used as an I/O pin.
PCINT14 (Pin Change Interrupt 14)

The PC6 pin can serve as an external interrupt source.
PC5A5 / D19ADC5 (ADC Input Channel 5)
PC5 can also be used as ADC input Channel 5. Note that ADC input channel 5 uses digital power (VCC).
SCL (2-wire Serial Bus Clock Line)

When the 2-wire Serial Interface (I2C) is enabled the PC5 pin is disconnected from the port and becomes the Serial Clock I/O pin for the 2-wire Serial Interface.
PCINT13 (Pin Change Interrupt 13)

The PC5 pin can serve as an external interrupt source.
PC4A4 / D18ADC4 (ADC Input Channel 4)
PC5 can also be used as ADC input Channel 4. Note that ADC input channel 5 uses digital power (VCC).
SDA (2-wire Serial Bus Data Input/Output Line)

When the 2-wire Serial Interface (I2C) is enabled the PC5 pin is disconnected from the port and becomes the Serial Data I/O pin for the 2-wire Serial Interface.
PCINT12 (Pin Change Interrupt 12)

The PC4 pin can serve as an external interrupt source.
PC3A3 / D17ADC3 (ADC Input Channel 3)
PC3 can also be used as ADC input Channel 3. Note that ADC input channel 3 uses analog power (AVCC).
PCINT11 (Pin Change Interrupt 11)

The PC3 pin can serve as an external interrupt source.
PC2A2 / D16ADC2 (ADC Input Channel 2)
PC2 can also be used as ADC input Channel 2. Note that ADC input channel 3 uses analog power (AVCC).
PCINT10 (Pin Change Interrupt 10)

The PC2 pin can serve as an external interrupt source.
PC1A1 / D15ADC1 (ADC Input Channel 1)
PC1 can also be used as ADC input Channel 1. Note that ADC input channel 3 uses analog power (AVCC).
PCINT9 (Pin Change Interrupt 9)

The PC1 pin can serve as an external interrupt source.
PC0A0 / D14ADC0 (ADC Input Channel 0)
PC0 can also be used as ADC input Channel 0. Note that ADC input channel 3 uses analog power (AVCC).
PCINT8 (Pin Change Interrupt 8)

The PC0 pin can serve as an external interrupt source.
Port PinArduino PinAlternate Function

PC6/ ~RESET

If the RSTDISBL Fuse is programmed, PC6 is used as an I/O pin. Note that the electrical characteristics of PC6 differ from those of the other pins of Port C.
If the RSTDISBL Fuse is unprogrammed, PC6 is used as a Reset input. A low level on this pin for longer than the minimum pulse length (2.5µs) will generate a Reset, even if the clock is not running.

Port D (PD7:0)

Port D is an 8-bit bi-directional I/O port with internal pull-up resistors (selected for each bit). The Port D output buffers have symmetrical drive characteristics with both high sink and source capability. As inputs, Port D pins that are externally pulled low will source current if the pull-up resistors are activated. The Port D pins are tri-stated when a reset condition becomes active, even if the clock is not running.

Port PinArduino PinAlternate Function
PD7D7AIN1 (Analog Comparator Negative Input)
Analog Comparator Negative Input Pin. Configure internal pull-up switched off and port pin as an input.
PCINT23 (Pin Change Interrupt 23)

The PD7 pin can serve as an external interrupt source.
PD6D6AIN0 (Analog Comparator Positive Input)
Analog Comparator Positive Input Pin. Configure internal pull-up switched off and port pin as an input.
OC0A (Timer/Counter0 Output Compare Match A Output)

This pin can serve as an external output for the Timer/Counter0 in Compare Match mode or PWM mode.
PCINT22 (Pin Change Interrupt 22)

The PD6 pin can serve as an external interrupt source.
PD5D5T1 (Timer/Counter 1 External Counter Input)
This pin can serve as an external output for the Timer/Counter1 in Compare Match mode or PWM mode.
OC0B (Timer/Counter0 Output Compare Match B Output)

This pin can serve as an external output for the Timer/Counter0 in Compare Match mode or PWM mode.
PCINT21 (Pin Change Interrupt 21)

The PD5 pin can serve as an external interrupt source.
PD4D4XCK (USART External Clock Input/Output)
USART external clock.
T0 (Timer/Counter 0 External Counter Input)

This pin can serve as an external output for the Timer/Counter0 in Compare Match mode or PWM mode.
PCINT20 (Pin Change Interrupt 20)

The PD4 pin can serve as an external interrupt source.
PD3D3INT1 (External Interrupt 1 Input)
The PD3 pin can serve as an external interrupt source
OC2B (Timer/Counter2 Output Compare Match B Output)

This pin can serve as an external output for the Timer/Counter2 in Compare Match mode or PWM mode.
PCINT19 (Pin Change Interrupt 19)

The PD3 pin can serve as an external interrupt source.
PD2D2INT0 (External Interrupt 0 Input)
The PD2 pin can serve as an external interrupt source.
PCINT18 (Pin Change Interrupt 18)

The PD2 pin can serve as an external interrupt source.
PD1D1TXD (USART Output Pin)
When the USART Transmitter is enabled, this pin is configured as an output regardless of the value of DDD1.
PCINT17 (Pin Change Interrupt 17)

The PD1 pin can serve as an external interrupt source.
PD0D0RXD (USART Input Pin)
When the USART Receiver is enabled this pin is configured as an input regardless of the value of DDD0.
PCINT16 (Pin Change Interrupt 16)

The PD0 pin can serve as an external interrupt source.
Port PinArduino PinAlternate Function

Arduino UNO PinOut and PinMux

Arduino UNO Pin Mapping with ATmega328P and Pin Functions
Arduino UNO Pin Mapping with ATmega328P and Pin Functions
Atmega328P ChipArduino UNO Pin NameArduino DescriptionAlternative Functions
PD0RX / D0Digital IO Pin 0 Serial RX Pin
PD1TX / D1Digital IO Pin 1 Serial TX Pin
PD2D2Digital IO Pin 2INT0
PD3D3Digital IO Pin 3Timer (OC2B) / INT1
PD4D4Digital IO Pin 4Timer (T0/XCK)
PD5D5Digital IO Pin 5Timer (OC0B/T1)
PD6D6Digital IO Pin 6Timer (OC0A) / AIN0
PD7D7Digital IO Pin 7AIN1
PB0D8Digital IO Pin 8Timer (CLK0/ICP1)
PB1D9Digital IO Pin 9Timer (OC1A)
PB2D10Digital IO Pin 10Timer (OC1B)
PB3D11Digital IO Pin 11SPI (MOSI) Timer (OC2A)
PB4D12Digital IO Pin 12SPI (MISO)
PB5D13Digital IO Pin 13SPI (SCK)
GNDGNDPower Ground
AREFAREFAnalog Reference
PC4SDA / D18Digital IO Pin 18I2C Data Pin / ADC4
PC5SCL / D19Digital IO Pin 19I2C Clock Pin / ADC5
Not Connected
VCCIOREFVoltage Reference (VCC)
PC6RESETReset (Active LOW)Digital IO Pin
3V3Power
VCC5V+5V Output from regulator or +5V regulated Input
GNDGNDGround
GNDGNDGround
VINUnregulated Supply
PC0A0 / D14Analog Input 0Digital IO Pin 14
PC1A1 / D15Analog Input 1Digital IO Pin 15
PC2A2 / D16Analog Input 2Digital IO Pin 16
PC3A3 / D17Analog Input 3Digital IO Pin 17
PC4A4 / D18Analog Input 4Digital IO Pin 18 / I2C (SDA)
PC5A5 / D19Analog Input 5Digital IO Pin 19 / I2C (SCL)
A6 / D20Analog Input 6Only Arduino NANO
A7 / D21Analog Input 7Only Arduino NANO

Arduino NANO PinOut and PinMux

Arduino NANO Pin Mapping with ATmega328P and Pin Functions
Arduino NANO Pin Mapping with ATmega328P and Pin Functions

Download PinMux Sheet


Crazy Engineer

MAKER - ENGINEER - YOUTUBER

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.