STM32开发板学习笔记(一)-- 开篇及STM32按键中断分析(续)
来源:互联网 发布:电信网络诈骗 编辑:程序博客网 时间:2024/04/30 11:18
那一篇写了几天,看着觉得太长了,还是重启一篇继续写下去。
上一篇说完了GPIO 。到此,如果加上几个按键捕获,就可以用按键控制灯了。那么如果要使用中断的话,要怎么做呢?
还是看例子吧,我真不知道怎么做。
在手册的 中断事件一章之中,有提到的是 中断向量控制器 (NVIC)和 外部中断/事件控制器 (EXIT)。而例子里面用到中断的里面也有 两个函数叫做:
void NVIC_Configuration(void); // void EXTI_Configuration(void);//Extern Interrput and Event controller configuration
好,先看 NVIC ,中断向量控制器。
/** * @brief NVIC Init Structure definition */typedef struct{ uint8_t NVIC_IRQChannel; /*!< Specifies the IRQ channel to be enabled or disabled. This parameter can be a value of @ref IRQn_Type (For the complete STM32 Devices IRQ Channels list, please refer to stm32f10x.h file) */ uint8_t NVIC_IRQChannelPreemptionPriority; /*!< Specifies the pre-emption priority for the IRQ channel specified in NVIC_IRQChannel. This parameter can be a value between 0 and 15 as described in the table @ref NVIC_Priority_Table */ uint8_t NVIC_IRQChannelSubPriority; /*!< Specifies the subpriority level for the IRQ channel specified in NVIC_IRQChannel. This parameter can be a value between 0 and 15 as described in the table @ref NVIC_Priority_Table */ FunctionalState NVIC_IRQChannelCmd; /*!< Specifies whether the IRQ channel defined in NVIC_IRQChannel will be enabled or disabled. This parameter can be set either to ENABLE or DISABLE */ } NVIC_InitTypeDef;
/** @defgroup NVIC_Priority_Table * @{ *//**@code The table below gives the allowed values of the pre-emption priority and subpriority according to the Priority Grouping configuration performed by NVIC_PriorityGroupConfig function ============================================================================================================================ NVIC_PriorityGroup | NVIC_IRQChannelPreemptionPriority | NVIC_IRQChannelSubPriority | Description ============================================================================================================================ NVIC_PriorityGroup_0 | 0 | 0-15 | 0 bits for pre-emption priority | | | 4 bits for subpriority ---------------------------------------------------------------------------------------------------------------------------- NVIC_PriorityGroup_1 | 0-1 | 0-7 | 1 bits for pre-emption priority | | | 3 bits for subpriority ---------------------------------------------------------------------------------------------------------------------------- NVIC_PriorityGroup_2 | 0-3 | 0-3 | 2 bits for pre-emption priority | | | 2 bits for subpriority ---------------------------------------------------------------------------------------------------------------------------- NVIC_PriorityGroup_3 | 0-7 | 0-1 | 3 bits for pre-emption priority | | | 1 bits for subpriority ---------------------------------------------------------------------------------------------------------------------------- NVIC_PriorityGroup_4 | 0-15 | 0 | 4 bits for pre-emption priority | | | 0 bits for subpriority ============================================================================================================================@endcode
貌似这个结构还比较简单,一个中断号,一个中断优先级,一个子优先级,还有一个开关。
这部分貌似没什么可说的,看下一个吧,外部中断事件控制器。
************************************************************************************************************************
外部中断/ 事件控制器由19 个产生事件/ 中断要求的边沿检测器组成。每个输入线可以独立地配置输入类型
(脉冲或挂起)和对应的触发事件(上升沿或下降沿或者双边沿都触发)。每个输入线都可以被独立的屏
蔽。挂起寄存器保持着状态线的中断要求。
要产生中断,必须先配置好并使能中断线。根据需要的边沿检测设置2 个触发寄存器,同时在中
断屏蔽寄存器的相应位写’1’ 允许中断请求。当外部中断线上发生了期待的边沿时,将产生一个
中断请求,对应的挂起位也随之被置’1’ 。在挂起寄存器的对应位写’1’ ,将清除该中断请求。
如果需要产生事件,必须先配置好并使能事件线。根据需要的边沿检测通过设置2 个触发寄存
器,同时在事件屏蔽寄存器的相应位写’1’ 允许事件请求。当事件线上发生了需要的边沿时,将
产生一个事件请求脉冲,对应的挂起位不被置’1’ 。
通过在软件中断/ 事件寄存器写’1’ ,也可以通过软件产生中断/ 事件请求。
EXTI寄存器结构,EXTI_TypeDef,在文件“stm32f10x_map.h”中定义如下:
typedef struct
{
vu32 IMR;
vu32 EMR;
vu32 RTSR;
vu32 FTSR;
vu32 SWIER;
vu32 PR;
} EXTI_TypeDef;
寄存器 描述
IMR 中断屏蔽寄存器
EMR 事件屏蔽寄存器
RTSR 上升沿触发选择寄存器
FTSR 下降沿触发选择寄存器
SWIR 软件中断事件寄存器
PR 挂起寄存器
************************************************************************************************************************
void EXTI_Configuration(void){EXTI_InitTypeDef EXTI_InitStruct; GPIO_EXTILineConfig(GPIO_PortSourceGPIOD, GPIO_PinSource3);//选择GPIO PD3 引脚作为外部中断线路EXTI_InitStruct.EXTI_Line = EXTI_Line3;EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt;//设置EXTI 模式为中断 。另外一个是 事件。EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Falling;//Falling down interruptEXTI_InitStruct.EXTI_LineCmd = ENABLE;EXTI_Init(&EXTI_InitStruct);}
/** * @brief EXTI Init Structure definition */typedef struct{ uint32_t EXTI_Line; /*!< Specifies the EXTI lines to be enabled or disabled. This parameter can be any combination of @ref EXTI_Lines */ EXTIMode_TypeDef EXTI_Mode; /*!< Specifies the mode for the EXTI lines. This parameter can be a value of @ref EXTIMode_TypeDef */ EXTITrigger_TypeDef EXTI_Trigger; /*!< Specifies the trigger signal active edge for the EXTI lines. This parameter can be a value of @ref EXTIMode_TypeDef */ FunctionalState EXTI_LineCmd; /*!< Specifies the new state of the selected EXTI lines. This parameter can be set either to ENABLE or DISABLE */ }EXTI_InitTypeDef;
怎么就突然看不下去了呢?
- STM32开发板学习笔记(一)-- 开篇及STM32按键中断分析(续)
- STM32开发板学习笔记(一)-- 开篇及STM32按键中断分析
- stm32学习笔记——按键(外部中断)
- STM32之中断(按键)
- stm32学习笔记(二)按键实验
- STM32按键中断学习记录
- stm32学习笔记(四)外部中断
- stm32学习笔记(七)定时器中断
- stm32 CT117E之按键(中断)
- stm32学习笔记——按键(扫描法)
- STM32学习笔记(一)----系统时钟
- stm32学习笔记(一) GPIO
- stm32学习笔记(一)时钟
- stm32学习笔记(一)点亮LED
- STM32学习笔记(2):外部中断的使用
- STM32学习笔记(2):外部中断的使用
- STM32学习笔记(2):外部中断的使用
- STM32学习笔记(2):外部中断的使用
- 关于面试的一些认识
- centos No package 'glib-2.0' found解决办法
- 采用C++的ACE库实现的一个通用的C/S架构通信程序(最终版)
- Hadoop -分布式环境搭建安装配置
- 图像处理中的全局优化技术(Global optimization techniques in image processing and computer vision) (一)
- STM32开发板学习笔记(一)-- 开篇及STM32按键中断分析(续)
- stl总结(转)
- javascript实现打印功能
- js关闭当前页面的几种方式
- STL中的常用的vector,map,set,sort, list用法笔记(转)
- Erlang如何查看gen_server内部的状态
- android 屏保
- 网络存储系统NSS基准性能测试(7.10)
- STL中: string、vector、list、deque、set、map 的区别(转)