我在使用STM32F103RE的EXTI功能时遇到了一些问题:先说我的设置吧,倍频到72MHz,使用PC0~PC5作为外部中断触发输入,同时打开了USART1和TIM3,使用Ver3.0版本的库函数;
遇到的问题是:当我使用信号发生器分别给PC0~PC5输入1KHZ的方波时,PC3、 PC4、PC5端口可以使程序正常运行,而给PC0、PC1、PC2加载方波信号后程序无**常运行,进入调试模式后,发现程序停止在了static void SetSysClockTo72(void)函数最后的循环处;当我将输入频率降低到100HZ后,一切就都正常了;
这是为什么?希望有用过的朋友指导一下,万分感谢!!
源代码如下:
void F122M_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure; //NVIC variables
GPIO_InitTypeDef GPIO_InitStructure; //GPIO variables
EXTI_InitTypeDef EXTI_InitStructure; //EXTI variables
/*--NVIC--*/
NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn; //更新事件,外部通道0
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; //抢占优先级0
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; //响应优先级0
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //允许中断
NVIC_Init(&NVIC_InitStructure); //写入设置
NVIC_InitStructure.NVIC_IRQChannel = EXTI1_IRQn; //更新事件,外部通道1
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; //抢占优先级0
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; //响应优先级1
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //允许中断
NVIC_Init(&NVIC_InitStructure); //写入设置
NVIC_InitStructure.NVIC_IRQChannel = EXTI2_IRQn; //更新事件,外部通道2
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; //抢占优先级0
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; //响应优先级1
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //允许中断
NVIC_Init(&NVIC_InitStructure); //写入设置
NVIC_InitStructure.NVIC_IRQChannel = EXTI3_IRQn; //更新事件,外部通道3
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; //抢占优先级0
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; //响应优先级1
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //允许中断
NVIC_Init(&NVIC_InitStructure); //写入设置
NVIC_InitStructure.NVIC_IRQChannel = EXTI4_IRQn; //更新事件,外部通道4
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; //抢占优先级0
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; //响应优先级1
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //允许中断
NVIC_Init(&NVIC_InitStructure); //写入设置
NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn; //更新事件,外部通道5
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; //抢占优先级0
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; //响应优先级1
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //允许中断
NVIC_Init(&NVIC_InitStructure); //写入设置
/*--GPIO--*/
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_AFIO, ENABLE); //PC端口时钟
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC,&GPIO_InitStructure); //配置外部中断线0~5 GPIO
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOC,&GPIO_InitStructure); //配置电源控制引脚 GPIO
/*--EXTI--*/
GPIO_EXTILineConfig(GPIO_PortSourceGPIOC,GPIO_PinSource0); //将PC0口用于外部中断事件检测,
GPIO_EXTILineConfig(GPIO_PortSourceGPIOC,GPIO_PinSource1); //将PC1口用于外部中断事件检测,
GPIO_EXTILineConfig(GPIO_PortSourceGPIOC,GPIO_PinSource2); //将PC2口用于外部中断事件检测,
GPIO_EXTILineConfig(GPIO_PortSourceGPIOC,GPIO_PinSource3); //将PC3口用于外部中断事件检测,
GPIO_EXTILineConfig(GPIO_PortSourceGPIOC,GPIO_PinSource4); //将PC4口用于外部中断事件检测,
GPIO_EXTILineConfig(GPIO_PortSourceGPIOC,GPIO_PinSource5); //将PC5口用于外部中断事件检测,
EXTI_ClearITPendingBit(EXTI_Line0); //清除线路挂起位
EXTI_ClearITPendingBit(EXTI_Line1);
EXTI_ClearITPendingBit(EXTI_Line2);
EXTI_ClearITPendingBit(EXTI_Line3);
EXTI_ClearITPendingBit(EXTI_Line4);
EXTI_ClearITPendingBit(EXTI_Line5);
EXTI_InitStructure.EXTI_Line = EXTI_Line0 | EXTI_Line1 | EXTI_Line2 | EXTI_Line3 | EXTI_Line4 | EXTI_Line5;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; //产生中断请求
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; //下降沿检测
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
}
调用顺序:
RCC_Configuration();
HW_Configuration();//配置USART,TIM3
/* Add your application code here
*/
F122M_Configuration();
中断函数:
/*******************************************************************************
* Function Name : EXTI0_IRQHandler
* Description : This function handles External interrupt Line 0 request.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void EXTI0_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line0) != RESET)
{
EXTI_ClearITPendingBit(EXTI_Line0);
count_0 = count_0 + 1;
}
}
/*******************************************************************************
* Function Name : EXTI1_IRQHandler
* Description : This function handles External interrupt Line 0 request.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void EXTI1_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line1) != RESET)
{
EXTI_ClearITPendingBit(EXTI_Line1);
count_1 = count_1 + 1;
}
}
/*******************************************************************************
* Function Name : EXTI2_IRQHandler
* Description : This function handles External interrupt Line 0 request.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void EXTI2_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line2) != RESET)
{
EXTI_ClearITPendingBit(EXTI_Line2);
count_2 = count_2 + 1;
}
}
/*******************************************************************************
* Function Name : EXTI3_IRQHandler
* Description : This function handles External interrupt Line 0 request.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void EXTI3_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line3) != RESET)
{
EXTI_ClearITPendingBit(EXTI_Line3);
count_3 = count_3 + 1;
}
}
/*******************************************************************************
* Function Name : EXTI4_IRQHandler
* Description : This function handles External interrupt Line 0 request.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void EXTI4_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line4) != RESET)
{
EXTI_ClearITPendingBit(EXTI_Line4);
count_4 = count_4 + 1;
}
}
/*******************************************************************************
* Function Name : EXTI9_5_IRQHandler
* Description : This function handles External interrupt Line 0 request.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void EXTI9_5_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line5) != RESET)
{
EXTI_ClearITPendingBit(EXTI_Line5);
count_5 = count_5 + 1;
}
} |