main函数开始设置时钟频率:
SetCLKtoMSI(RCC_MSIRange_6);我的数据格式是:@*xxxxxxxxxxxxxxxxx#,总共20个字符,开头先判断数据是否是有效数据,是的话就复制到USART_BUF1里面。时钟频率是16M的时候功能都是正常的,都可以使用,但是4M的时候就不能用了,求大神解答。
然后串口中断函数:
void USART1_IRQHandler(void)
{
int i = 0;
if(USART_GetITStatus(USART1, USART_IT_RXNE) == SET)
{
USART_ClearITPendingBit(USART1,USART_IT_RXNE);
dataBuffer1[RxCounter++]= USART_ReceiveData(USART1);
USART_SendData(USART1,USART_ReceiveData(USART1));
if(RxCounter >= 255)
{
memset(dataBuffer1, 0, sizeof(dataBuffer1));
RxCounter = 0;
return;
}
for(i = 0; i < RxCounter; i++)
{
if((dataBuffer1[i] == '@') && (dataBuffer1[i+1] == '*'))
{
if(i+20 <= RxCounter)
{
strncpy(USART_BUF1, (char*)&dataBuffer1[i], 20);
memset(dataBuffer1, 0, sizeof(dataBuffer1));
RxCounter = 0;
}
}
}
}
}
|