標題:
單片機與GPRS模塊串口通信不穩(wěn)定,如何解決
[打印本頁]
作者:
會飛的大象
時間:
2019-11-26 07:53
標題:
單片機與GPRS模塊串口通信不穩(wěn)定,如何解決
在單片機與GPRS模塊通信中,出現(xiàn)串口通信不穩(wěn)定的問題,有時候指令發(fā)不出去,一直找不到原因,會不會是定時器中斷的影響,請大神指教
作者:
51hei**1140
時間:
2019-11-26 10:40
沒有程序,沒有原理圖,不好分析
作者:
小黑屋525
時間:
2019-11-26 11:31
會不會是你發(fā)送的頻率太快了?????
作者:
會飛的大象
時間:
2019-11-26 22:08
if(sim_ready_flag==1&&csq_test_end_falg==0) //判斷SIM卡是否準備就緒,信號檢測結(jié)束標識是否是0
{
if(csq_send_flag==0&&csq_send_frequ!=0) //判斷指令發(fā)送標識及發(fā)送次數(shù)
{
send_string(csq); //發(fā)送網(wǎng)絡(luò)信號檢測指令
csq_send_frequ--;
csq_send_flag=1;
wait_2s=2;
timing_2s_end_flag=0;
}
if(csq_send_flag==1&&timing_2s_end_flag==1) //判斷指令是否發(fā)出及計時是否結(jié)束
{
if(strstr(Rec_buf,"OK")!=NULL) //判斷返回數(shù)據(jù)中是否包含‘OK’字符串
{
if(Rec_buf[8]=='9'&&Rec_buf[9]=='9') //判斷檢測的信號強度是否是99
{
if(csq_send_frequ==0) //判斷發(fā)送是否結(jié)束
{
csq_test_flag=0; //信號測試標識值0
net_connect_flag=0; //關(guān)閉網(wǎng)絡(luò)連接
}
}
else
{
csq_test_flag=1; //信號測試標識值1
csq_send_frequ=0;
}
csq_send_flag=0;
sig_strength_num[0]=Rec_buf[8]; //提取信號強度值
sig_strength_num[1]=Rec_buf[9];
Clr_Rec_buf();
}
else //如果返回數(shù)據(jù)中不包含‘OK’字符串,則檢測失敗
{
csq_send_flag=0;
if(csq_send_frequ==0) //判斷發(fā)送是否結(jié)束
{
csq_test_flag=0; //信號測試標識值0
net_connect_flag=0; //關(guān)閉網(wǎng)絡(luò)連接
gprs_p=0;
}
Clr_Rec_buf();
}
if(csq_send_frequ==0) //判斷發(fā)送是否結(jié)束
{
csq_test_end_falg=1; //信號檢測結(jié)束標識值1
sim_ready_flag=0;
}
}
}
/************檢測網(wǎng)絡(luò)注冊狀態(tài)************/
if(csq_test_flag==1&&creg_test_end_flag==0) //判斷信號檢測是否成功,網(wǎng)絡(luò)狀態(tài)測試結(jié)束標識是否為0
{
if(creg_send_flag==0&&creg_send_frequ!=0) //判斷指令是否發(fā)出及發(fā)送次數(shù)
{
send_string(creg); //發(fā)送網(wǎng)絡(luò)注冊狀態(tài)指令
creg_send_frequ--;
creg_send_flag=1;
wait_2s=2;
timing_2s_end_flag=0;
}
if(creg_send_flag==1&&timing_2s_end_flag==1) //判斷指令是否發(fā)出及計時是否結(jié)束
{
if(strstr(Rec_buf,"OK")!=NULL&&(Rec_buf[11]=='1'||Rec_buf[11]=='5')) //判斷返回字符串是否包含‘OK’,網(wǎng)絡(luò)注冊狀態(tài)是‘1’或‘5’
{
creg_succ_flag=1; //注冊成功標識值1
creg_send_frequ=0; //發(fā)送次數(shù)值0
creg_send_flag=0;
Clr_Rec_buf();
}
else
{
creg_send_flag=0;
if(creg_send_frequ==0) //判斷發(fā)送是否結(jié)束
{
creg_succ_flag=0; //注冊成功標識值0
net_connect_flag=0; //關(guān)閉連接
gprs_p=0;
}
Clr_Rec_buf();
}
if(creg_send_frequ==0) //判斷發(fā)送是否結(jié)束
{
creg_test_end_flag=1; //網(wǎng)絡(luò)注冊狀態(tài)測試結(jié)束標識值1
//csq_test_flag=0;
}
}
}
/************GPRS附著狀態(tài)************/
if(creg_succ_flag==1&&cgatt_test_end_falg==0) //判斷網(wǎng)絡(luò)注冊是否成功,GPRS附著狀態(tài)檢測結(jié)束標識是否為0
{
if(cgatt_send_flag==0&&cgatt_send_frequ!=0) //判斷指令是否發(fā)送及發(fā)送次數(shù)
{
//Clr_Rec_buf();
send_string(cgatt); //發(fā)送測試指令
cgatt_send_frequ--;
cgatt_send_flag=1;
wait_2s=4;
timing_2s_end_flag=0;
}
if(cgatt_send_flag==1&&timing_2s_end_flag==1) //判斷指令是否發(fā)出及計時是否結(jié)束
{
if(strstr(Rec_buf,"OK")!=NULL&&Rec_buf[10]=='1')
{
cgatt_test_flag=1; //GPRS附著檢測標識值1
cgatt_send_frequ=0; //發(fā)送次數(shù)值0
cgatt_send_flag=0;
Clr_Rec_buf();
}
else
{
cgatt_send_flag=0;
if(cgatt_send_frequ==0) //判斷發(fā)送是否結(jié)束
{
cgatt_test_flag=0; //GPRS附著檢測標識值0
net_connect_flag=0; //關(guān)閉網(wǎng)絡(luò)連接
gprs_p=0;
}
Clr_Rec_buf();
}
if(cgatt_send_frequ==0)
{
creg_succ_flag=0;
cgatt_test_end_falg=1; //GPRS附著檢測結(jié)束標識值1
}
}
}
/************設(shè)置APN************/
if(cgatt_test_flag==1&&cstt_set_end_falg==0) //判斷GPRS附著檢測標識值
{
if(cstt_send_flag==0&&cstt_send_frequ!=0) //判斷指令是否發(fā)送及發(fā)送次數(shù)
{
send_string(cstt); //發(fā)送設(shè)置APN指令
cstt_send_frequ--;
cstt_send_flag=1;
wait_2s=3;
timing_2s_end_flag=0;
;
}
if(cstt_send_flag==1&&timing_2s_end_flag==1) //判斷指令是否發(fā)送及計時是否結(jié)束
{
if(strstr(Rec_buf,"OK")!=NULL) //判斷返回字符串是否包含“OK”
{
cstt_set_flag=1; //APN設(shè)置標識值1
cstt_send_frequ=0;
cstt_send_flag=0;
Clr_Rec_buf();
}
else
{
cstt_send_flag=0;
if(cstt_send_frequ==0) //判斷發(fā)送是否結(jié)束
{
cstt_set_flag=0; //APN設(shè)置標識值0
net_connect_flag=0;
gprs_p=0;
}
Clr_Rec_buf();
}
if(cstt_send_frequ==0)
{
cgatt_test_flag=0; //GPRS附著檢測標識值0
cstt_set_end_falg=1;
}
}
}
/*****建立無線鏈路(GPRS或者CSD)*****/
if(cstt_set_flag==1&&ciicr_set_end_falg==0) //判斷APN設(shè)置狀態(tài)標識
{
if(ciicr_send_flag==0&&ciicr_send_frequ!=0) //判斷指令是否發(fā)送及發(fā)送次數(shù)
{
send_string(ciicr); //發(fā)送建立無線鏈路指令
ciicr_send_frequ--;
ciicr_send_flag=1;
wait_2s=3;
t_1s=0;
timing_2s_end_flag=0;
}
if(ciicr_send_flag==1&&timing_2s_end_flag==1) //判斷指令是否發(fā)送及計時是否結(jié)束
{
if(strstr(Rec_buf,"OK")!=NULL)
{
ciicr_set_flag=1; //無線鏈路設(shè)置標識值1
ciicr_send_frequ=0;
cstt_set_flag=0; //APN設(shè)置狀態(tài)標識值0
ciicr_set_end_falg=1;
ciicr_send_flag=0;
for(i=0;i<24;i++)
str2[i]=Rec_buf[i];
Clr_Rec_buf();
}
else
{
n++;
if(n<4)
{
wait_2s=3;
t_1s=0;
timing_2s_end_flag=0;
}
if(n==4) //判斷發(fā)送是否結(jié)束
{
ciicr_send_flag=0;
//Clr_Rec_buf();
n=0;
}
if(ciicr_send_frequ==0)
{
ciicr_set_flag=0; //無線鏈路設(shè)置標識值0
cstt_set_flag=0; //APN設(shè)置狀態(tài)標識值0
ciicr_set_end_falg=1;
net_connect_flag=0; //關(guān)閉網(wǎng)絡(luò)連接
gprs_p=0;
}
for(i=0;i<24;i++)
str2[i]=Rec_buf[i];
Clr_Rec_buf();
}
}
}
ciicr這條指令就是發(fā)不出去,其他的都正常
作者:
小黑屋525
時間:
2019-11-27 09:09
我室友之前也調(diào)過一個GPRS的模塊,也是很不穩(wěn)定,一方面是那個模塊是個便宜貨,60一個,其次是舍內(nèi)信號不好,天線都是那衣叉頂出窗戶外面去的,如果你這個一直無法發(fā)送的話,可以把你程序里面寫一個串口發(fā)送的字符串神馬的,用串口助手看看進到這個if里面沒有,程序沒問題再找找硬件的問題,要對照在使用手冊,放平心態(tài)一步一步地檢查;
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1