2.把PB3设置成外部中断输入模式,写出EXTI配置程序和NVIC配置程序(模式2:占先优先级和副优先级各2位),其他设置不做要求。
时间: 2024-02-17 18:00:11 浏览: 35
好的,以下是EXTI和NVIC的配置程序:
EXTI配置程序:
```c
// PB3作为外部中断输入模式
GPIO_InitTypeDef GPIO_InitStruct;
GPIO_InitStruct.Pin = GPIO_PIN_3;
GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING; // 下降沿触发中断
GPIO_InitStruct.Pull = GPIO_PULLUP; // 上拉
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
// EXTI中断线3配置
HAL_EXTI_DeInit();
EXTI_HandleTypeDef EXTI_InitStruct;
EXTI_InitStruct.Line = EXTI_LINE_3;
EXTI_InitStruct.Mode = EXTI_MODE_INTERRUPT;
EXTI_InitStruct.Trigger = EXTI_TRIGGER_FALLING; // 下降沿触发
EXTI_InitStruct.Pull = EXTI_PULLUP;
HAL_EXTI_Init(&EXTI_InitStruct);
```
NVIC配置程序:
```c
HAL_NVIC_SetPriority(EXTI3_IRQn, 0x01, 0x01); // 占先优先级为1,副优先级为1
HAL_NVIC_EnableIRQ(EXTI3_IRQn); // 开启外部中断3中断
```
以上两个程序需要在main函数中调用,同时需要在stm32fxxx_it.c文件中实现EXTI3_IRQHandler()函数来处理中断。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.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)