7. Stm32f407 key external interrupt

                                7. Stm32f407 key external interrupt

 

Hardware platform: stm32f407ve

Software platform: win10 (OS Name: Microsoft Windows 10 Enterprise

                                  OS Version:                10.0.18363 N/A Build 18363)

             Keil5 5.26.2

             HAL Library Version: 2.14.0 (currently downloaded the latest)

Time: 2020-02-13

 

Chinese interrupt this part of the need to refer to manuals and authoritative guide.

Here I mention this thing NVIC, stands Nested vectored interrupt controller, namely Nested Vectored Interrupt Controller. This device is used to manage all stm32 interrupt (the permissions in real life, analogous to the telecom operators, telephone operators do not give you, and that your phone is not out of the fight), NVIC does not allow the interrupt trigger interrupt, then no matter how the interrupt settings, or how to trigger, will not cause cpu response (interrupt).

 

So our program is bound to set part of the NVIC, after all interrupts to be set, should pay attention to this part of the set of NVIC, NVIC is simple to set only interrupt priority and interrupt enable can be. In the end which interrupt or preempt other first response to this is NVIC interrupt management category.

 

 

Stm32f4 interrupt priority is rather special, it can only set a total of 16 interrupts, the smaller the number, the higher the priority. (Arm chip in the design, it can support more priority (128 or 256), but more priority means more sophisticated interrupt priority management circuit, more complex logic, more power, stm32 in the design trade-offs made, but basically speaking, the 16 priority interrupt or to meet most of the application).

 

16 interrupt only 4 bits to meet, four (binary) bits can be represented by the number 16, is provided on part of the priority interrupt is provided only four high priority register on it, the lower 4 bits invalid (Why choose high four, can refer to authoritative guidebook, st company is considering a program compatibility issues).

 

Stm32f4 this series can also be divided into priority preemption priority and the priority of the response, the sum of their two or 16.

My program is initialized in HAL_init interrupt priority assignment

 

There is a detailed description of our program settings are 16 preemption priority.

NVIC_PRIORITYGROUP_0: 0 bits for preemption priority no preemption priority

                      4 bits for subpriority 16 level response interrupt

NVIC_PRIORITYGROUP_1: 1 bits for preemption priority level 2 interrupt preemption

                     3 bits for subpriority 8 interrupt level response

NVIC_PRIORITYGROUP_2: 2 bits for preemption priority level 4 interrupt preemption

                      2 bits for subpriority level 4 interrupt response   

NVIC_PRIORITYGROUP_3: 3 bits for preemption priority 8 preemptive interrupt

                     1 bits for subpriority level 2 interrupt response

NVIC_PRIORITYGROUP_4: 4 bits for preemption priority 16 preemptive priority

                     0 bits for subpriority no response priority

 

 

 

Finally, there is the interrupt handler

Interrupt handler principles:

  1. In the case of meet the functional, it should be the sooner the better, not blocking, not causing obstruction of the function call to get the semaphore lock or the like.
  2. 没有返回值,没有参数(这基本是所有中断函数的特点)。
  3. 尽量不使用printf函数,这个也是会引起阻塞的
  4. 要清除中断标志

 

我们的中断处理比较简单:

翻转led,因为按键是机械形变,所有会造成机械抖动,在电信号的部分产生抖动信号,所以实际按键的时候,并不是按一下,翻转一下led,有可能等保持不变,或者变化很多次。这都是电路抖动引起的,具体的话可以参考一下消抖部分(大部分都是延时处理,因为我觉得中断应尽量的快,就不使用别人的延时了,我也就不演示了哈,后期可以使用定时器去定时扫描按键的部分,讲到定时器的时候,我们说一下这个部分)。

github的工程源码:

https://github.com/zhaozhi0810/stm32f407_hal_keil5

 

 

 

发布了24 篇原创文章 · 获赞 18 · 访问量 1万+

Guess you like

Origin blog.csdn.net/zhaozhi0810/article/details/104290912