找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2511|回復(fù): 4
打印 上一主題 下一主題
收起左側(cè)

單片機與GPRS模塊串口通信不穩(wěn)定,如何解決

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:247342 發(fā)表于 2019-11-26 07:53 | 只看該作者 回帖獎勵 |正序瀏覽 |閱讀模式
在單片機與GPRS模塊通信中,出現(xiàn)串口通信不穩(wěn)定的問題,有時候指令發(fā)不出去,一直找不到原因,會不會是定時器中斷的影響,請大神指教
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報

5#
ID:546770 發(fā)表于 2019-11-27 09:09 | 只看該作者
我室友之前也調(diào)過一個GPRS的模塊,也是很不穩(wěn)定,一方面是那個模塊是個便宜貨,60一個,其次是舍內(nèi)信號不好,天線都是那衣叉頂出窗戶外面去的,如果你這個一直無法發(fā)送的話,可以把你程序里面寫一個串口發(fā)送的字符串神馬的,用串口助手看看進到這個if里面沒有,程序沒問題再找找硬件的問題,要對照在使用手冊,放平心態(tài)一步一步地檢查;
回復(fù)

使用道具 舉報

地板
ID:247342 發(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ā)不出去,其他的都正常
回復(fù)

使用道具 舉報

板凳
ID:546770 發(fā)表于 2019-11-26 11:31 | 只看該作者
會不會是你發(fā)送的頻率太快了?????
回復(fù)

使用道具 舉報

沙發(fā)
ID:648281 發(fā)表于 2019-11-26 10:40 | 只看該作者
沒有程序,沒有原理圖,不好分析
回復(fù)

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復(fù) 返回頂部 返回列表