RVMDK环境,开发板上只引出了USART1这一个串口。通过查询方式和PC通讯,没有问题,接收到PC发出的字节并发送回PC。现在想通过中断方式通讯,设置断点,发现始终未进入中断服务程序。程序很简单,一些初始化设置而已,网上搜了不少例程,找不出问题原因。请教各位达人。
代码如下:
----------------------------------------------
/*-------------- main.c --------------*/
int main(void)
{
RCC_Configuration();
NVIC_Configuration();
GPIO_Configuration();
USART_Configuration();
while(1)
{
}
}
void RCC_Configuration(void)
{
SystemInit();
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_USART1,ENABLE);
}
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
|
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA,&GPIO_InitStructure);
}
void USART_Configuration(void)
{
USART_InitTypeDef USART_InitStructure;
USART_InitStructure.USART_BaudRate = 115200;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None
USART_Init(USART1,&USART_InitStructure);
USART_ITConfig(USART1,USART_IT_RXNE,ENABLE);
USART_ITConfig(USART1,USART_IT_TXE,ENABLE);
USART_Cmd(USART1,ENABLE);
}
/*-------- stm32f10x_it.c ---------*/
void USART1_IRQHandler(void)
{
u16 c;
if (SET == USART_GetFlagStatus(USART1, USART_FLAG_RXNE))
{
c = USART_ReceiveData(USART1);
USART_SendData(USART1, c);
while (RESET == USART_GetFlagStatus(USART1, USART_FLAG_TC));
}
}
---------------------------------------------------
如果不配置NVIC,而在main()的while(1)中添加