Send SMS with STM32l152 and SIM900

為{幸葍}努か 提交于 2019-12-13 05:03:32

问题


I send the SMS "Hello World", but on my cellular I get this message ATAT+CMGS="xxxxxx">HelloWorld instead. What can be causing this?

 void controlAT()
{ 
 clearString();  
     wait_ms(100);      
    SIM900.printf("AT\r");
      wait_ms(1000);
if(result=="\r\nOK\r\n") {
 pc.printf("\r\n----OK AT----\r\n");
}else {
     pc.printf("-- ERROR AT --");           
}
pc.printf("%s",result.c_str());     
 }
 /*send SMS */
void sendSMS_Raw()
{
clearString();
SIM900.printf("AT+CMGS=");
SIM900.printf("\"");
SIM900.printf("+xxxxxxxxxxxxx");    
SIM900.printf("\"");
SIM900.printf("\r");
SIM900.printf("Hello World");
SIM900.printf("\r");
SIM900.putc(0x1A); 
wait_ms(200);
pc.printf("%s",result.c_str());     
clearString();  
})
 /**MAIN**/
 int main() {
pc.printf("\r\n GSM 900 TEST\n"); 
SIM900.attach(&callback_rx);    
SIM900.baud(9600); 
wait_ms(100);
      while(1) {

    wait(1.0); // 1 sec
   pc.printf("\r\n---MAIN---\n"); 
    controlAT();            
    sendSMS_Raw();  
        pc.printf("\r\n---FINE---\n"); 

     wait(2.0); // 1 sec

    }
} 

回答1:


the fix it in this metod:

   void sendSMS_Raw()
 {
 pc.printf("\r\n----sendSMS2----\r\n");  
 clearString();
 SIM900.printf("AT+CMGS=");
 SIM900.printf("\"");
 SIM900.printf("+xxxxxxxxx");   
 SIM900.printf("\"");
 SIM900.printf("\r");
 wait_ms(200);      // this create the problem
 SIM900.printf("Hello");
 SIM900.printf("\r");
 SIM900.putc(0x1A); 
 wait_ms(200);
  pc.printf("%s",result.c_str());       
 clearString();                 
 }

thank for all.



来源:https://stackoverflow.com/questions/31454683/send-sms-with-stm32l152-and-sim900

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!