STM32 Study Notes sorting (2) External interruptions

Source: Internet
Author: User
Tags table definition
I have been learning STM32 for almost a year. Now I am working on the STM32 platform. I will summarize the basic knowledge of STM32 when the workload is relatively small a year ago, in the case of no accident, you will be able to continuously release complete notes. During the course, you will primarily follow the wild fire tutorial, and then sort out the appropriate notes. 2.1c C configuration 1. Interrupt group configuration

I have been learning STM32 for almost a year. Now I am working on the STM32 platform. I will summarize the basic knowledge of STM32 when the workload is relatively small a year ago, in the case of no accident, you will be able to continuously release complete notes. During the course, you will primarily follow the wild fire tutorial, and then sort out the appropriate notes. 2.1 configure Objective C 1. Interrupt group in configuration

I have been learning STM32 for almost a year. Now I am working on the STM32 platform. I will summarize the basic knowledge of STM32 when the workload is relatively small a year ago, in the case of no accident, you will be able to continuously release complete notes. During the course, you will primarily follow the wild fire tutorial, and then sort out the appropriate notes. 2.1 configure Objective C 1. Interrupt Group

When configuring the priority, Objective C can only configure the priority of 16 kinds of Interrupt vectors. the preemption priority and response priority are determined by a four-digit number, assign the four digits to the preemptible priority and response priority.

There are five group allocation methods:

Group 0th: all four digits are used to configure the response priority.

1st groups: the highest priority of one-bit preemptible, and the lower priority of Three-bit response. 2 ^ 1 = 2 preemption priorities (0, 1), 2 ^ 3 = 8 response priorities,

2nd group: two-bit preemptible priority, Two-Bit response priority. Four preemptible priorities and four response priorities.

3rd group: Priority of priority for priority three-Bit Allocation and response priority for one-bit allocation. 8 preemption priorities and 2 response priorities.

Group 4th: all four-digit preemptible priority. The 16 types of Interrupt vectors are preemptible attributes without response attributes.

2. Interrupt priority

1. STM32 interrupt vectors have preemptible attributes and response attributes. The smaller the number, the higher the level.

2. preemptible refers to the attribute that interrupts other interruptions, that is, nested interruptions may occur because of this attribute.

3. response. When the preemptible priority of two interrupt vectors is the same, if the two interrupts arrive at the same time, the system first processes the interruptions with a higher response priority.

3. interrupted Channels

The interrupt service function name must be consistent with the interrupt vector table definition in the Startup File startup_stm32f10x_hd.s (The following is the corresponding table)

Interrupt channel interrupt service function interrupt line interrupt pin

EXTI0_IRQn EXTI0_IRQHandler; EXTI Line 0 PA0 ~ PG0

Exti?irqn exti=irqhandler; EXTI Line 1 PA1 ~ PG1

EXTI2_IRQn EXTI2_IRQHandler; EXTI Line 2 PA2 ~ PG2

EXTI3_IRQn EXTI3_IRQHandler; EXTI Line 3 PA3 ~ PG3

EXTI4_IRQn EXTI4_IRQHandler; EXTI Line 4 PA4 ~ PG4

EXTI9_5_IRQn EXTI9_5_IRQHandler; EXTI Line 9 .. 5

EXTI15_10_IRQn EXTI15_10_IRQHandler; EXTI Line 15... 10

4. Code

Static void NVIC_A11exti_inti (void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig (NVIC_PriorityGroup_1); // select interrupt Group 1

NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn; // select the interrupt channel 0.
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; // preemptible interrupt priority settings
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; // response interrupt priority setting
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; // ENABLE interruption
NVIC_Init (& NVIC_InitStructure );
}

2.1 External Interrupt Configuration

1. Enable the EXTIx line clock and the second function AFIO clock

2. Configure the interrupt priority (Priority C) of the EXTIx line)

3. Configure the GPIO pin

4. Configure EXTI mode and interrupt line


Void EXTI_PA0_inti (void)
{
GPIO_InitTypeDef GPIO_InitStructure; // defines the structure of GPIO macro operations
EXTI_InitTypeDef EXTI_InitStructure; // defines the struct of the EXTI macro operation.
EXTI_ClearITPendingBit (EXTI_Line0); // clear the interrupt flag

/* Config the exitline clock and AFIO clock */
RCC_APB2PeriphClockCmd (RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE); // enable gpio clock


/* Config the same C */
NVIC_A11exti_inti (); // configuration interruption


/* EXTI line gpio config */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; // select the pin number
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD; // pull the input
GPIO_Init (GPIOA, & GPIO_InitStructure); // configure the output

/* EXYI line mode config */
GPIO_EXTILineConfig (GPIO_PortSourceGPIOA, GPIO_PinSource0); // select the interrupt pin
EXTI_InitStructure.EXTI_Line = EXTI_Line0; // select the disconnection line 0.
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; // set it to interrupt request, not an event request
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; // The Descent edge is interrupted.

EXTI_InitStructure.EXTI_LineCmd = ENABLE; // ENABLE external interrupt
EXTI_Init (& EXTI_InitStructure );
}


2.1 service function void EXTI0_IRQHandler (void)
{
If (EXTI_GetITStatus (EXTI_Line0 )! = RESET)
{
// Uart_sendStr (USART1, "q ");
EXTI_ClearITPendingBit (EXTI_Line0 );
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.