将AT命令从stm32发送到sim 800时出错

时间:2016-06-12 21:25:44

标签: stm32

我正在尝试将AT命令发送到stm32,但是在发送AT命令时出现错误

#include "mbed.h"
#include <string>
Serial pc(SERIAL_TX, SERIAL_RX); // pc comunication
Serial SIM900(PA_9, PA_10);   //tx, rx SIM 900
string result;
char x;

void clearString()
 {
  result.clear();
 }

 }
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 --");           //this is a error
 }
 pc.printf("%s",result.c_str());     
 }

void sendSMS()
{
 pc.printf("\r\n----sendSMS2----\r\n");  
 clearString();
 SIM900.printf("AT+CMGS=");
 SIM900.printf("\"");
 SIM900.printf("074xxxxx");   
 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(); 

}


int main() {    

pc.printf("\r\n GSM 900 TEST\n"); 

SIM900.baud(9600)
wait_ms(200);


 controlAT();
 wait_ms(200);
 sendSMS();  // SEND SMS     
 wait_ms(200);      



}

我在controlAT()函数中遇到错误,它总是打印 pc.printf(“ - ERROR AT - ”); //这是一个错误

请帮我解决此问题

1 个答案:

答案 0 :(得分:0)

你的代码看起来不对,你清楚&#34;结果&#34;但你永远不会设置它。

应该有像...这样的一行     导致= SIM900.print ...