本帖最后由 iangzy 于 2017-4-24 21:22 编辑
我这里的中断为何经常无法接收到数据?数据丢失了void USART1_Init(void)
{
GPIO_Init(GPIOC, GPIO_Pin_3, GPIO_Mode_Out_PP_High_Fast); //TXD //txd初始化为高电平互补推挽输出模式
GPIO_Init(GPIOC, GPIO_Pin_2, GPIO_Mode_In_PU_No_IT); //RXD //rxd初始化为不带中断上拉输入模式
CLK_PeripheralClockConfig (CLK_Peripheral_USART1,ENABLE);//开启USART时钟
USART_Init(USART1,115200,USART_WordLength_8b,USART_StopBits_1,USART_Parity_No,USART_Mode_Tx|USART_Mode_Rx);//设置USART参数115200,8N1,接收/发送
USART_ITConfig (USART1,USART_IT_RXNE,ENABLE);//使能接收中断
USART_Cmd (USART1,ENABLE);//使能USART
}
INTERRUPT_HANDLER(USART1_RX_TIM5_CC_IRQHandler,28)
{
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/
u8 res=0;
if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)
{
USART_ClearITPendingBit (USART1,USART_IT_RXNE);//清中断标志
res = USART_ReceiveData8 (USART1);
if(USART_RX_STA<500)
{
USART_RX_count=0;
if(USART_RX_STA==0)
{
USART_RX_count_enable = 1;
}
USART_RX_BUF[USART_RX_STA++]=res;
}
else
{
USART_RX_STA|=1<<15;
}
}
}
|