最近在调试STM32F105的串口1,发现开接收中断后,没有数据发给给USART1,接收缓冲区中数据也在变化,并在上位机发数据,进入中断,缓冲区中不是上位发的数据,请问怎么解决?谢谢。void SGL_USART1_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
USART_DeInit(USART1);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
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_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART1, &USART_InitStructure);
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
USART_Cmd(USART1, ENABLE);
/* USART1 GPIO Configuration */
/* Configure USART1 Tx (Pb.06) as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Configure USART1 Rx (Pb.7) as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* USART1 NCIV Interrupt Configuration */
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void USART1_IRQHandler(void)
{
if(USART_GetITStatus(USART1, USART_IT_RXNE)!=RESET)
{ /* Read one byte from the receive data register */
USART_ClearITPendingBit(USART1, USART_IT_RXNE);
SGL_SCI1_RcvData[RxCounter++] = USART_ReceiveData(USART1);//USART1->DR;//(USART_ReceiveData(USART1) & 0x8F);
/* Clear the USART1 Receive interrupt */
}
if(USART_GetFlagStatus(USART1,USART_FLAG_ORE)!=RESET)
{
USART_ClearFlag(USART1,USART_FLAG_ORE); //?SR
USART_ReceiveData(USART1); //?DR
}
}
|