0

嗨,我正在使用 arduino 和 sim800l,我编写了一个代码来读取短信并将其写入串行,但我不知道为什么它只读取消息中的前 12 个字符并将其余字符删掉。代码:

#include <SoftwareSerial.h>

//Create software serial object to communicate with SIM800L
SoftwareSerial mySerial(2, 3); //SIM800L Tx & Rx is connected to Arduino #3 & #2

void setup()
{
  //Begin serial communication with Arduino and Arduino IDE (Serial Monitor)
  Serial.begin(9600);
  
  //Begin serial communication with Arduino and SIM800L
  mySerial.begin(9600);

  Serial.println("Initializing..."); 
  delay(1000);

  mySerial.println("AT"); //Once the handshake test is successful, it will back to OK
  updateSerial();
  
  mySerial.println("AT+CMGF=1"); // Configuring TEXT mode
  updateSerial();
  mySerial.println("AT+CNMI=1,2,0,0,0"); // Decides how newly arrived SMS messages should be handled
  updateSerial();
}

void loop()
{
  updateSerial();
}

void updateSerial()
{
  delay(500);
  while (Serial.available()) 
  {
    mySerial.write(Serial.read());//Forward what Serial received to Software Serial Port
  }
  while(mySerial.available()) 
  {
    Serial.write(mySerial.read());//Forward what Software Serial received to Serial Port
  }
}

非常简单的代码并且在各个方面都可以正常工作,唯一的问题是读取消息中的前 12 个字符,然后像我发送消息一样将其余字符删掉:

hello

很好,但是当我发送此消息时:

hello 123456789

消息长度为 15,串行我只得到前 12 个:

hello 123456

其余的就像它根本不存在:(

你能帮我为什么吗?如果你能告诉我如何解决它?

4

0 回答 0