element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
RoadTests & Reviews
  • Products
  • More
RoadTests & Reviews
Blog Arm Education: Internet of Things Course - Interrupts and Low Power Features
  • Blog
  • RoadTest Forum
  • Documents
  • RoadTests
  • Reviews
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join RoadTests & Reviews to participate - click to join for free!
  • Share
  • More
  • Cancel
  • Author Author: ralphjy
  • Date Created: 26 May 2019 10:07 PM Date Created
  • Views 525 views
  • Likes 1 like
  • Comments 0 comments
Related
Recommended
  • RoadTest
  • arm education iot course

Arm Education: Internet of Things Course - Interrupts and Low Power Features

ralphjy
ralphjy
26 May 2019

The fifth course module examines the use of interrupts and the programming of the interrupt handler to improve program and power efficiency.  The lab for this module shows how to change the program in Lab4 from using polling to using interrupts.

 

image

 

This module goes over the different types of interrupts and how the Interrupt Handler operates.  The Interrupt Handler needs to run in Privileged Mode so that it has access to core functions in the processor.  The handler uses the Nested Vector Interrupt Controller (NVIC) and the Interrupt Service Routine to execute the interrupt.  It also covers Masks, Priority, and Latency and described how execution is resumed post interrupt.

 

image

 

Lab Exercise - Interrupt and Low power Features

The lab introduces the use of what they call "drivers" but I normally think of as library or auxiliary modules, i.e function definitions are now moved into external files to improve the readability of the main file.

image

 

The new program functionality is the setup for interrupt handling which is in the interrupts.c file.

 

/*----------------------------------------------------------------------------
 Interrupts C file
 *----------------------------------------------------------------------------*/
#include "interrupts.h"
#include "stm32f4xx.h"


void init_interrupts(void){
//Start clock for the SYSCFG
RCC->APB2ENR |= RCC_APB2ENR_SYSCFGEN;

//Enable debug in low-power modes
DBGMCU->CR |= DBGMCU_CR_DBG_SLEEP | DBGMCU_CR_DBG_STOP | DBGMCU_CR_DBG_STANDBY;

//Setup interrupt configuration register for interrupts
SYSCFG->EXTICR[3] |= SYSCFG_EXTICR4_EXTI13_PC;



EXTI->IMR  |= (EXTI_IMR_MR13); //set the interrupt mask
EXTI->FTSR |= (EXTI_FTSR_TR13); //trigger on a falling edge

__enable_irq();

//Set priority
NVIC_SetPriority(EXTI15_10_IRQn, 0);

//Clear pending interrupts
NVIC_ClearPendingIRQ(EXTI15_10_IRQn);


//Enable interrupts
NVIC_EnableIRQ(EXTI15_10_IRQn);

}


// *******************************ARM University Program Copyright (c) ARM Ltd 2014*************************************

 

 

The other difference is the Wait For Interrupt (wfi) instruction in the main program to enter low power mode:

/*----------------------------------------------------------------------------
 MAIN function
 *----------------------------------------------------------------------------*/


int main() {
   // Initialise LEDs and buttons
  init_led();
  init_button();
  init_interrupts();

  while(1){
   __wfi(); //Wait for interrupts
  }
}

 

Here is the excerpt from the reference manual: (the link on the lab page is broken - http://www.st.com/web/en/resource/technical/document/reference_manual/DM00096844.pdf )

image

 

The main apparent difference is that the LED now toggles on each button press rather than turning on for the button press and turning off when the button is released.  This is due the interrupt only triggering on the button press (falling edge of GPIO pin).  I can measure a difference of about -10mA power supply current between the previous lab's program and the current one..

  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube