我的stm32 中断为什么进不去,都弄了好几天了,郁闷啊!
望高手指教,代码如下:
#include <stm32f10x.h>
#include "stm32f10x_it.h"
void UART2_GPIO_Configuration(void);
void UART2_Configuration(void);
void NVIC_Configuration(void);
void delay(uint32_t nCount);
int main()
{
SystemInit();
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_AFIO, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
NVIC_Configuration();
UART2_GPIO_Configuration();
UART2_Configuration();
while(1)
{
这里不停的发送那个变量的值,初始值为0,进入接受中断后更改其值
}
}
/*********************************配置UART2的GPIO口*************************************/
void UART2_GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
// Configure USART1_Tx as alternate function push-pull
GPIO_XXXXXXXXXXXXXXXXIO_Pin = GPIO_Pin_2;
GPIO_XXXXXXXXXXXXXXXXIO_Speed = GPIO_Speed_50MHz;
GPIO_XXXXXXXXXXXXXXXXIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
// Configure USART1_Rx as input floating
GPIO_XXXXXXXXXXXXXXXXIO_Pin = GPIO_Pin_3;
GPIO_XXXXXXXXXXXXXXXXIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
//GPIO_PinRemapConfig(GPIO_Remap_USART2, ENABLE); //复用重映射UART2
}
/************************************配置串口2参数***********************************/
void UART2_Configuration(void)
{
USART_InitTypeDef USART_InitStructure;
USART_XXXXXXXXXXXXXXXXART_BaudRate = 115200;
USART_XXXXXXXXXXXXXXXXART_WordLength = USART_WordLength_8b;
USART_XXXXXXXXXXXXXXXXART_StopBits = USART_StopBits_1;
USART_XXXXXXXXXXXXXXXXART_Parity = USART_Parity_No ;
USART_XXXXXXXXXXXXXXXXART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_XXXXXXXXXXXXXXXXART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART2, &USART_InitStructure);
USART_ITConfig(USART2, USART_IT_RXNE, ENABLE); //使能UART2接收中断
USART_Cmd(USART2, ENABLE);
}
/*******************************************************************************
* Function Name : NVIC_Configuration
* Description : Configures NVIC and Vector Table base location.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
/* Configure one bit for preemption priority */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
中断服务程序如下:
if(USART_GetITStatus(USART2, USART_IT_RXNE) != RESET)
{
/* Disable SC_USART RXNE Interrupt */
在这里我通更改一个变量的值,然后再主函数里继续死循环的发送。
}
但是,一旦从电脑上通过串口发送个数据,就死掉了,是怎么回事啊!
200字以内,仅用于支线交流,主线讨论请采用回复功能。