Received messages get messed up after running for some time

I'm having some problems using a SIM900 module with my UNO. After some time of listening to a NeoSWSerial connection (same with SoftwareSerial) I only receive a huge mess of data. The interesting thing is, that if I have this issue and I try to send a SMS (sending is always possible) the connection "gets" healed. It looks like that there is an overflow within the NeoSWSerial of the receive buffer. Does anyone have any idea what I can try? Attached you find the part of the code which is relevant:

bool waitForSMS() {
  if (SIM900.available() != 0) {
    incoming_message = "";
    unsigned long lastmillis = millis();
    int i = 0;
    memset(rx_buffer, EOS, 200);    // Initialize the string
    while((lastmillis + 100)>millis()){
      while (SIM900.available() != 0) {
        rx_buffer[i] =;

    incoming_message = String(rx_buffer);
    if (incoming_message.startsWith(startPattern)) {
      incoming_message = removeFirstLine(incoming_message, startPattern);
      return true;
    } else if (!incoming_message.startsWith("AT+CMGF=1")) {
      SIM900.print("AT+CMGF=1\r"); //try to "heal" connection
  return false;

By the way, I use a fixed baudrate for the SIM900


Hope someone can help me.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.