STM32 interrupt programming to teach you to get the trilogy will interrupt settings and interrupt priority settings

       Stm32 interrupt as an essential function, and its importance is self-evident and therefore good to stop learning is fundamental.

  So today to interrupt a good knowledge about eating configuration, the saying goes: quicken work. What problem is it? Project I used a touch keyboard TTP229, results when testing the keyboard, you can not enter a password? In the end, the debugger is a priority bug affected due to the interruption.

  The project is to use STM32F030C8 types of MCU, we can download from the official to the standard library file to start assembly file, view this type MCU external interrupt vector table. (As shown below)

  First, we look at what NVIC Shi, NVIC structure in core_cm0.h standard library file in.

  Among them, we generally use the ISER, ICER, IP these three registers. ISER used to enable interrupts, ICER to clear the interrupt, IP is used to set the interrupt priority.

  Secondly, we look at interrupt priority, the interrupt priority register NVIC_IPRx, this register is 8 bits, in principle, each external interrupt priority can be configured from 0 to 255, in fact streamlined, it only uses high 4 bit. These four bits, and is divided into two priority preemption priority and in response, then the interrupt priority has divided into the following situations:

  1, different preemption priority, will involve nested interrupts, preemption priority high priority will preempt lower priority, priority to be implemented. (Note: The lower the priority number, the higher the priority)

  2, the same priority preemption, not related to nested interrupts, in response to different priority, a high priority response to the response. (Example: two interrupts while responding, where it will first perform the high priority interrupt response) (Note: The lower the priority number, the higher the priority)

  3, in response to priority and preemption priority are the same, the number thereof hardware interrupt, the interrupt smaller the number, the higher the priority. (Hardware interrupt number from the interrupt vector table to see them)

  Interrupt priority grouping, because interrupt priority uses only high four, so the interrupt priority packets respectively following situations:

  

  Finally, to sum up the interrupt program trilogy:

  The first step: an interrupt enable peripherals, specifically from the corresponding interrupt enable bits.

  (: Clock must be turned on before we GPIO port to use GPIO, used EXTI must turn AFIO clock for example)

  第二步:初始化NVIC_InitTypeDef结构体,配置中断优先级分组,设置抢占优先级和响应优先级,使能中断请求。

  库函数:

  NVIC_IRQChannel()设置不同的中断源,在IRQn_Type IRQn结构体寻找自己对应的中断源。

  NVIC_IRQChannelPreemptionPriority()设置抢占优先级

  NVIC_IRQChannelCmd() 中断使能或者取消使能

  第三步:编写中断服务函数,在stm32f0xx_it.c文件中,都有一个根据中断向量表,实现的一个空的中断服务函数,需要我们自己重新编写。

 

stm32相关的视频资料

(stm32直流电机驱动)
http://www.makeru.com.cn/live/1392_1218.html?s=45051

(时钟系统)
http://www.makeru.com.cn/live/1392_1082.html?s=45051
STM32中断系统
http://www.makeru.com.cn/live/3523_1745.html?s=45051
STM32可以这样玩
http://www.makeru.com.cn/live/4034_1460.html?s=45051
分析STM32的的开发方式
http://www.makeru.com.cn/live/3523_1673.html?s=45051

Guess you like

Origin www.cnblogs.com/923327iu/p/12052973.html