Engineers Garage

  • Electronics Projects and Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe

Using External Interrupts in LPC1768- (Part 7/21)

By Prabakaran P.M March 2, 2016

This is the Article to introduce the programming of external interrupt in ARM Cortex-M3 LPC1768 Microcontroller. Here we are going to do input and output functions of GPIO of LPC1768. For better understanding we are going to use a button and the LED. Our idea is to program in such a way that when the button is pressed the external interrupt is triggered and the LED will be ON. Setting up the Environment for the development of ARM cortex M3 is well discussed in this article.

The LPC 1768 is ARM Cortex- M3 based Microcontrollers for embedded application features in low power consumption and a high level of integration. The ARM Cortex M3 is designed in a such way to enhance debug features and a higher level of system integration. It clocks at a CPU frequency of 100 MHz, and incorporates a 3-stage pipeline and uses a Harvard architecture with separate local instruction and data buses for third bus peripherals. The ARM Cortex- M3 CPU have an internal pre-fetch unit to support speculative branching. The peripheral components include 512KB of flash memory, 64kb of data memory, Ethernet MAC, USB OTG, 4 UART’s, 8-channel general purpose DMA controller, 2 SSP Controllers, 10-bit DAC, Quadrature encoder interface, SPI interface, 3 I2C bus interface, 2 input plus 2 outputs I2S bus interface, 4 general purpose timers, ultra-low power Real-Time Clock (RTC) with separate battery supply, and up to 70 general purpose I/O pins, 6-output general purpose PWM. The LPC1768/66/65/64 are pin-compatible with the 100-pin LPC236x ARM7-based Microcontroller series.


Interrupts are signals from a hardware part that can pause the current code and jump to execute a separate piece of code. An example: An interrupt from an IO ports can be used to turn an LED ON, instead of checking if the IO port is high or low. The interrupt executes the code and the user doesn’t have to worry about checking the IO port in the main code.

The ARM Interrupts:

The ARM interrupts are grouped into two

  • The Non maskable interrupt which are associated with the ARM core, once they are occurring ARM will vector to the relevant routine. Example of NMI is System tick.

  • The maskable interrupts which are associated with the External peripheral devices of ARM, which accepts interrupt requests only when they are enabled in the NVIC (Nested Vector Interrupt Controller). Each interrupt is associated with an interrupt number that is used in programming the NVIC.

Nested vector interrupt controller:

All interrupts, including core exceptions are managed by the NVIC core exceptions are always accepted. External interrupts are maskable, that is when an event occurs the peripheral will sent an interrupt request if the associated bit in the NVIC is enabled the interrupt will be accepted and forwarded to the associated vector and interrupt service routine. In the LPC1768/66/65/64, the NVIC supports 33 vectored interrupts. All interrupts are serviced in low latency since NVIC is closely associated with the core. NVIC also supports some advanced interrupt handling modes including Interrupt preemption, tail chaining, late arrival. These are the reasons why ARM has low latency and robust response. Regarding priority, every interrupt has associated an 8-bit priority level register. But not all bits are used to set priorities. LPC1768 has 32 priority levels, which means that 4 MSB bits are used to set priorities. The lower the priority number the highest priority of the interrupt. If needed, these bits can be split into two groups where you can create sub-priority level. Subpriority levels are handy when two or more same priority level interrupts occur. Then one with a higher subpriority will be handled first.

Handling external interrupts:

Each peripheral device has one interrupt line connected to the NVIC but may have several interrupt flags. Individual interrupts flags may also represent more than one interrupt source. Any pin on PORT0 and PORT2 (total of 42 pins) regardless of the selected function, can be programmed to generate an interrupt on a rising edge, a falling edge, or both. External interrupts are connected to NVIC through a special external interrupt controller (EXTI). It allows to map multiple GPIO lines to NVIC external interrupt inputs

Steps to setup an interrupt on a GPIO port:

We will be using pin P0.26 as the external interrupt pin. We must configure the microcontroller appropriately.

  1. First modify the PINSEL0 register to change the function of pin P0.26 from general purpose IO (GPIO) to external interrupt 3 (EINT3).

  2. Set the direction of the pin P0.26 as input.

  3. Set internal pull-up or pull-low, according to the type of interrupt which is Rising or Falling.

Create a project using Keil uvision4 for LPC1768 Microcontroller:

In this section, we will start creating a project in Keil MDK we have already installed Keil µVision and Co-MDK Plug-in + CoLinkEx Drivers required for the CoLinkEx programming adapter. You can start by downloading the project files and kick start your practical experiment.

Code.rar

Code Description:

To setup and interrupt the command IOSetInterrupt(Portnum, Bitposition, Direction); is used. Portnum and Bitposition are for the IO port used. Direction is the direction of the interrupt. An interrupt can be rising edge or falling edge.

A correct instruction how to setup an falling edge interrupt on IO port 0.26 is:

IOSetInterrupt(0, 26, 0);

Dir 0 is for a falling edge.

To handle the interrupts the following code has to be placed under the main code:

void EINT3_IRQHandler (void)

{

       IOClearInterrupt();

}

Every time a GPIO interrupt happens, the code in the EINT3_IRQHandler() will be executed. The command IOClearInterrupt(); is needed, it will let the interrupt handler know that the interrupts are processed. If the interrupt is not cleared with the command IOClearInterrupt(), the code EINT3_IRQHandler will be in a loop forever.

If GPIO interrupts on multiple pins are used, the code in EINT3_IRQHandler will be executed for every interrupt. To check which pin generated an interrupt, the command IOCheckInterrupts(Portnum, Direction); is used. The command returns a 32 bit variable. If the return value is 1, then an interrupt occurred on the GPIO pin.

There are two ways to check if an interrupt occurred on a specific pin. This example uses pin P0.26.  checkvalue = GPIOCheckInterrupts(0, 0);

if (checkvalue == (1 << 26))

{

//Code to execute if interrupt happened

}

The above code example is to check for an interrupt on port 0,26 and switches an LED on accordingly.

Using External Interrupts in LPC1768 Prototype

Fig. 1: Using External Interrupts in LPC1768 Prototype

Project Source Code

###
 
The codes are linked in Description ###

Circuit Diagrams

Circuit-Diagram-Using-External-Interrupts-in-LPC1768

Project Components

  • LED
  • Resistor

Project Video


Filed Under: ARM

 

Next Article

← Previous Article
Next Article →

Questions related to this article?
👉Ask and discuss on EDAboard.com and Electro-Tech-Online.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

EE TECH TOOLBOX

“ee
Tech Toolbox: Internet of Things
Explore practical strategies for minimizing attack surfaces, managing memory efficiently, and securing firmware. Download now to ensure your IoT implementations remain secure, efficient, and future-ready.

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


RSS EDABOARD.com Discussions

  • i need an embedded c program that will read a 12 bit memory address from the io pins and output the data to pins from the memory in a 8051 mcontroller
  • DIY Buck Boost Converter using XL6019
  • Getting Started with Electronics: What Helped You the Most in the Beginning?
  • De-embedding using Y, Z parameter
  • Simple Active Bandpass Filter Oscillates

RSS Electro-Tech-Online.com Discussions

  • parallel-to-serial problem
  • 12v battery, 18v magic
  • STM32 checking self-written delay function
  • Behringer MX 1602 mixer - reading block diagram
  • Reclaiming missing motherboard header

Featured -USB Series

  • Controller Chip Selection for Developing USB Enabled Device (Part 6/6)
  • Signal and Encoding of USB System (Part 5/6)
  • USB Requests and Stages of Control Transfer (Part 4/6)
  • USB Descriptors and their Types (Part 3/6)
  • USB Protocol: Types of USB Packets and USB Transfers (Part 2/6)
  • Introduction to USB: Advantages, Disadvantages and Architecture (Part 1/6)

Recent Articles

  • Littelfuse driver achieves less than 1 µA standby current for energy-efficient designs
  • Microchip optimizes power consumption in transceiver-less FPGA design for automotive applications
  • What is an IoT platform and when is one useful?
  • Silanna launches laser driver IC with sub-2 ns FWHM pulse for LiDAR application
  • LEM introduces current sensors with bandwidth up to 2.5 MHz for precision applications

EE ENGINEERING TRAINING DAYS

engineering

Submit a Guest Post

submit a guest post
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy

Search Engineers Garage

  • Electronics Projects and Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe