|
|
代碼附上:
/*******************************************************************************
* 函 數 名 : USART1_IRQHandler
* 函數功能 : USART1中斷函數
* 輸 入 : 無
* 輸 出 : 無
*******************************************************************************/
u16 Recive_data[10];
u16 rxLength;
u16 f;
void USART1_IRQHandler(void) //串口1中斷服務程序
{
u8 r;
u16 rxLength=0;
//接收中斷(接收到的數據必須是0x0d 0x0a結尾)
if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)
{
for(f=0;f<7;f++){
Recive_data[rxLength]=USART_ReceiveData(USART1);//(USART1->DR); //讀取接收到的數據
USART_SendData(USART1,Recive_data[rxLength]);
//
if(Recive_data[rxLength]=='\n'){
break;}
else
{
rxLength++;
// printf("%d",rxLength);
}
printf("%d",rxLength);
//
}
if(Recive_data[0]=='A')
{
printf("正常!\n");
}
if(Recive_data[1]=='T')
{
printf("很正常!\n");
}
if(Recive_data[0]=='A' && Recive_data[1]=='T')
{
printf("請繼續!\n");
}
if(Recive_data[0]=='A' && Recive_data[1]=='T'&& Recive_data[2]=='+')
{
printf("非常正常!\n");
}
while(USART_GetFlagStatus(USART1,USART_FLAG_TC) != SET);
}
USART_ClearFlag(USART1,USART_FLAG_TC);
}
想著串口發送AT指令,然后STM32控制相應元件實現對應功能
但是串口助手上明顯不對啊
|
|