RCC_APB2Periph_SYSCFG在哪个头文件定义了
时间: 2023-12-21 09:07:37 浏览: 26
RCC_APB2Periph_SYSCFG位于STM32的寄存器映射表中,对应的头文件为"stm32f4xx_rcc.h",在该头文件中可以找到如下定义:
#define RCC_APB2Periph_SYSCFG ((uint32_t)0x00004000) /*!< SYSCFG clock enable */
同时,还需要包含stm32f4xx.h头文件才能使用这个宏定义。
相关问题
exti.c 文件代码如下: void EXTIX_Init(void) { NVIC_InitTypeDef NVIC_InitStructure; EXTI_InitTypeDef EXTI_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE); SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOE, EXTI_PinSource0); EXTI_InitStructure.EXTI_Line = EXTI_Line0; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; //上升沿触发 EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init( &EXTI_InitStructure ); //中断 NVIC 配置 NVIC_InitStructure.NVIC_IRQChannel=EXTI0_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x00; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x02; NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE; NVIC_Init(&NVIC_InitStructure); } (3)编写 LED 与 KEY 相关代码。 (4)编写中断服务函数。 主函数代码如下: //包含相关头文件 int main(void) { NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); delay_init(168); LED_Init(); KEY_Init(); EXTIX_Init(); LED0=0; while(1) { } } 4.4 实验练习 在实验 4.3 的框架中补齐代码,以 SW0(E0)做为外部中断输入引脚控制 LED 的亮灭。
LED 与 KEY 相关代码如下:
```
void LED_Init(void) {
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOF, &GPIO_InitStructure);
}
void KEY_Init(void) {
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOE, &GPIO_InitStructure);
}
```
中断服务函数如下:
```
void EXTI0_IRQHandler(void) {
if (EXTI_GetITStatus(EXTI_Line0) != RESET) {
LED0 = !LED0;
EXTI_ClearITPendingBit(EXTI_Line0);
}
}
```
完整代码如下:
```
#include "stm32f4xx.h"
#include "delay.h"
#define LED0 PFout(9)
#define LED1 PFout(10)
#define KEY PEin(0)
void LED_Init(void) {
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOF, &GPIO_InitStructure);
}
void KEY_Init(void) {
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOE, &GPIO_InitStructure);
}
void EXTIX_Init(void) {
NVIC_InitTypeDef NVIC_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOE, EXTI_PinSource0);
EXTI_InitStructure.EXTI_Line = EXTI_Line0;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; //上升沿触发
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init( &EXTI_InitStructure ); //中断 EXTI 配置
NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x00;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x02;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure); //中断 NVIC 配置
}
int main(void) {
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
delay_init(168);
LED_Init();
KEY_Init();
EXTIX_Init();
LED0 = 0;
while(1) {
}
}
void EXTI0_IRQHandler(void) {
if (EXTI_GetITStatus(EXTI_Line0) != RESET) {
LED0 = !LED0;
EXTI_ClearITPendingBit(EXTI_Line0);
}
}
```
void EXTI_Init(void);在stm32ll库中怎么使用?
在STM32 LL库中,可以使用以下步骤来初始化外部中断(External Interrupt):
1. 确保已经包含了相关的头文件:
```c
#include "stm32f4xx_ll_exti.h"
#include "stm32f4xx_ll_gpio.h"
#include "stm32f4xx_ll_bus.h"
#include "stm32f4xx_ll_rcc.h"
```
2. 在主函数之外,定义一个名为 `EXTI_Init` 的函数,并在函数体内进行外部中断的初始化配置:
```c
void EXTI_Init(void) {
// 使能外部中断时钟
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_SYSCFG);
// 配置外部中断的中断线
LL_SYSCFG_SetEXTISource(LL_SYSCFG_EXTI_PORTC, LL_SYSCFG_EXTI_LINE13);
// 配置外部中断触发方式为上升沿触发
LL_EXTI_EnableRisingTrig_0_31(LL_EXTI_LINE_13);
// 使能外部中断
LL_EXTI_EnableIT_0_31(LL_EXTI_LINE_13);
// 设置外部中断的优先级
NVIC_SetPriority(EXTI15_10_IRQn, 0);
// 使能外部中断的中断向量
NVIC_EnableIRQ(EXTI15_10_IRQn);
}
```
3. 在主函数中调用 `EXTI_Init` 函数来进行外部中断的初始化:
```c
int main(void) {
// ...
EXTI_Init();
// ...
}
```
注意,以上代码是一个示例,具体的引脚和触发方式的配置可能会因具体的硬件连接和需求而有所不同。在实际应用中,您需要根据您的硬件电路和需求进行适当的配置和修改。