求助,STM8S 串口一直接收中断,跳不出来!
[复制链接]
程序一直在中断,跳不出来!标志位也清0了,没用
串口初始化:
void Uart_Init(void)
{
UART1_DeInit();
UART1_Init((u32)115200, UART1_WORDLENGTH_8D, UART1_STOPBITS_1, \
UART1_PARITY_NO , UART1_SYNCMODE_CLOCK_DISABLE , UART1_MODE_TXRX_ENABLE);
UART1_ITConfig(UART1_IT_RXNE_OR,ENABLE );
//UART1_ITConfig(UART1_IT_TXE, DISABLE);
UART1_Cmd(ENABLE );
}
串口接收:
u8 UART1_ReceiveByte(void)
{
u8 USART1_RX_BUF;
while (UART1_GetFlagStatus(UART1_FLAG_RXNE) == RESET);
USART1_RX_BUF=UART1_ReceiveData8();
return USART1_RX_BUF;
}
中断函数:
@far @interrupt void UART1_RX_IRQHandler(void)
{
u8 Res;
if(UART1_GetITStatus(UART1_IT_RXNE)!= RESET)
{
//UART1_ClearFlag(UART1_FLAG_RXNE);
//UART1_ClearITPendingBit(UART1_IT_RXNE);
/*接收中断(接收到的数据必须是0x0d 0x0a结尾)*/
//Res =UART1_ReceiveData8();
Res =UART1_ReceiveByte();
//UART1_ClearITPendingBit(UART1_IT_RXNE);
//UART1_ClearFlag(UART1_FLAG_RXNE);
/*(USART1->DR);读取接收到的数据,当读完数据后自动取消RXNE的中断标志位*/
if(( UART_RX_NUM&0x80)==0)/*接收未完成*/
{
if( UART_RX_NUM&0x40)/*接收到了0x0d*/
{
//UART1_SendString("33333...",sizeof("33333..."));
if(Res!=0x0a) UART_RX_NUM=0;/*接收错误,重新开始*/
else UART_RX_NUM|=0x80; /*接收完成了 */
}
else /*还没收到0X0D*/
{
if(Res==0x0d)
{
UART_RX_NUM|=0x40;
UART1_SendString("55555...",sizeof("55555..."));
}
else
{
RxBuffer[UART_RX_NUM&0X3F]=Res ;
UART_RX_NUM++;
UART1_SendString("33333...",sizeof("33333..."));
//UART1_GetFlagStatus(UART1_FLAG_OR);
#if 1
if( UART_RX_NUM>63)
{
UART_RX_NUM=0;/*接收数据错误,重新开始接收*/
UART1_SendString(" 44444",sizeof(" 44444"));
}
#endif
}
}
}
//UART1_SendString("666666",sizeof("666666"));
}
}
主函数:
int main(void)
{
unsigned char i=0;
/* Infinite loop */
/*设置内部时钟16M为主时钟*/
CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);
/*!
Uart_Init();
K_line_uart_Init();
enableInterrupts();
while (1)
{if(UART_RX_NUM&0x80)
{
UART1_SendString("1010...",sizeof("1010..."));
len=UART_RX_NUM&0x3f;/*得到此次接收到的数据长度*/
UART1_SendString("You sent the messages is:",sizeof("You sent the messages is"));
UART1_SendString(RxBuffer,len);
UART1_SendByte('\n');
UART_RX_NUM=0;
}
}
while循环一直不执行 求哪位大神指教下 谢谢 在线等!