HT32F52352设置中断优先级的库函数
时间: 2023-12-08 21:05:03 浏览: 111
HT32F52352是一款基于ARM Cortex-M3内核的微控制器,它的中断控制器支持优先级分组和优先级预分配。在HT32F52352中,每个中断源都有一个对应的中断优先级,可以通过设置中断优先级来控制中断的响应顺序。
HT32F52352的中断优先级设置可以使用以下库函数:
1. `void NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority)`
该函数用于设置指定中断源的中断优先级,其中IRQn参数指定中断源,priority参数指定中断优先级。优先级的取值范围是0~15。
2. `void NVIC_SetPriorityGrouping(uint32_t PriorityGroup)`
该函数用于设置中断优先级分组方式,PriorityGroup参数指定分组方式。HT32F52352支持4种分组方式,分别是:
- NVIC_PRIORITYGROUP_0:优先级分组为0,没有亚优先级。
- NVIC_PRIORITYGROUP_1:优先级分组为1,有1位亚优先级。
- NVIC_PRIORITYGROUP_2:优先级分组为2,有2位亚优先级。
- NVIC_PRIORITYGROUP_3:优先级分组为3,有3位亚优先级。
3. `uint32_t NVIC_EncodePriority(uint32_t PriorityGroup, uint32_t PreemptPriority, uint32_t SubPriority)`
该函数用于将中断优先级编码成32位数值,可以用于设置NVIC_SetPriority函数的priority参数。PriorityGroup参数指定分组方式,PreemptPriority参数指定抢占优先级,SubPriority参数指定亚优先级。
例如,设置USART1的中断优先级为抢占优先级2,亚优先级1,可以使用以下代码:
```
NVIC_SetPriority(USART1_IRQn, NVIC_EncodePriority(NVIC_PRIORITYGROUP_2, 2, 1));
```
需要注意的是,中断优先级越低,优先级数值越大。另外,如果多个中断源的优先级相同,则按照它们在向量表中的顺序响应。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)