STM32 MCU (2) External interrupt

Publisher:真诚友谊Latest update time:2018-05-19 Source: eefocusKeywords:STM32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Study Materials

Li Xiang stm32 video tutorial 49 episodes  http://pan.baidu.com/s/1kTyt03P   STM32 interrupts (upper, middle and lower) external interrupts (registers, library functions)
STM32 function description (Chinese).pdf     http://download.csdn.net/detail/leytton/7630851
Interrupt management function.pdf   http://wenku.baidu.com/view/b90e5b82360cba1aa811dad3.html


Unnamed

17 - EXTI line 16 connected to PVD output

18 - EXTI line 17 connected to the RTC alarm event

19 - EXTI line 18 connected to USB wake-up event

 

Note: From the above figure, we can see that the pins connected to EXTI0 are PA0, PB0, PC0, PD0, PE0, PF0, PG0, and other external interrupts EXTI1——

EXTI15 is similar. So when using, try to configure the required external interrupts on different EXTIx.

      For example, if three external interrupts are needed, we can configure them to PA0, PB4, and PG3. At this time, each interrupt has its own interrupt handler.

     If PA0, PB0, and PC1 are configured, PA0 and PB0 will share an interrupt program segment.

     It can be designed like this.

===========================================dividing line==========================================

Configuration usage:

  1. Initialize the corresponding GPIO pins

  2. Configure external interrupt sources and connect interrupt sources to GPIO

  3. Write the interrupt handler for the corresponding interrupt source

===========================================dividing line==========================================

code

  • Initialize the corresponding GPIO pins

GPIO_InitTypeDef GPIO_InitStructure;


RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);           
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);


GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;   
GPIO_Init(GPIOE, &GPIO_InitStructure);


GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8|GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;   
GPIO_Init(GPIOB, &GPIO_InitStructure);

Note: GPIO multiplexing function must be turned on, as shown in the red part

  • Configure external interrupt sources and connect interrupt sources to GPIO


GPIO_EXTILineConfig(GPIO_PortSourceGPIOE, GPIO_PinSource0);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOE, GPIO_PinSource1);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource8);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource9);

 
EXTI_InitStructure.EXTI_Line = EXTI_Line0|EXTI_Line1|EXTI_Line8|EXTI_Line9;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);

  • Write the interrupt handler for the corresponding interrupt source


void EXTI0_IRQHandler(void)
{
  if(Sys_Status > MIN_STATUS)
  {
    Sys_Status --;
  }
  EXTI_ClearITPendingBit(EXTI_Line0);
}


void EXTI1_IRQHandler(void)
{
  PEout(2) = ~PEout(2);
  EXTI_ClearITPendingBit(EXTI_Line1);
}


#define Exti_From_Pin8 0x00000100
#define Exti_From_Pin9 0x00000200

void EXTI9_5_IRQHandler(void)
{

  u32 Temp = 0x00; 

  PEout(2) = ~PEout(2);
  Temp = EXTI->PR;       //取读是那个引脚的中断
  switch(Temp)
  {
    case Exti_From_Pin8:
      EXTI_ClearITPendingBit(EXTI_Line8);
      break;
    case Exti_From_Pin9:
      if(Sys_Status < MAX_STATUS)
      {
        Sys_Status ++;
      }
      EXTI_ClearITPendingBit(EXTI_Line9);
      break;
    default:break;
  }
}

===========================================dividing line==========================================

Interrupt handler description: Since external interrupts EXTI5-EXTI9 share an interrupt (EXTI10-EXTI15 are similar),

Differentiating different interrupt sources requires corresponding judgment. As shown in EXTI9_5_IRQHandler above, the judgment is made by reading the EXTI->PR register.

The source of the interrupt.


Keywords:STM32 Reference address:STM32 MCU (2) External interrupt

Previous article:STM32 MCU (3) Serial port interrupt communication
Next article:STM32 MCU (1) Summary of learning materials + reference manual + LED light

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号