ESP32 SIM800L File.Available() & File.Read() Issue - Inverted question mark ⸮

cattledog:
How do you know the data on the SD card is clean? Can you read it in a computer and see what you have?

Can you write a minimal example program which demonstrates your issue. For example if you input 100 characters from serial, perform the concatenated read and then print an output, can you produce a failure? Or does the failure involve the SD card reading?

I have made a minimal example as well, where i just read data from sd card and print it on serial monitor. This runs without any error.

#include <SPI.h>
#include <Wire.h>
#include <SD.h>

#include "FS.h"
#include "SD.h"

//char* file_name1 = "/basic.png";
//char* file_name1 = "/xl.xlsx";
char* file_name1 = "/data2.txt";
char char_buffer;
String string_buffer = "";
int buffer_space = 1000;
File File1;

SPIClass SPI1(HSPI);
#define MY_CS       33
#define MY_SCLK     18
#define MY_MISO     19
#define MY_MOSI     32

int answer2 = 0;
void setupSDCard()
{
    SPI1.begin(MY_SCLK, MY_MISO, MY_MOSI, MY_CS);
    //Assuming use of SPI SD card
    if (!SD.begin(MY_CS, SPI1)) {
        Serial.println("Card Mount Failed");
    } else {
        Serial.println("SDCard Mount PASS");
        String size = String((uint32_t)(SD.cardSize() / 1024 / 1024)) + "MB";
        Serial.println(size);
    }
}

void setup() {
  Serial.begin(19200);
  delay(10);
  setupSDCard();


 
//  Serial.println("Starting...");
//  read_char_function();
//  Serial.println("The end...");
}
void loop() {

    File1 = SD.open(file_name1);
    if (File1) {
    Serial.println("Opening the file: " + String(file_name1) + " done.");
    }else {
    Serial.println("Error opening " + String(file_name1));
    while(true);
    }
  
  // put your main code here, to run repeatedly:
  Serial.println("Starting...");
  if(answer2 == 0){
  answer2 = read_char_function();
  }
  if(answer2 == 1){
  Serial.println("The end...");
  answer2 = 2;
  }
}

byte read_char_function(){
  int answer = 0;
    if (File1) {
      int i = 0;
      while (File1.available()>0) {                                    
        char_buffer = File1.read();//Takes one by one character in char_buffer from File.read()
        string_buffer.concat(char_buffer);//Concats every single character from char_buffer and makes string_buffer
        i++;
        if (i == buffer_space) {
          Serial.println("string_buffer: " + String(string_buffer));
          string_buffer = "";
          i = 0;
        }
      }
      if (string_buffer != ""){
        Serial.println("string_buffer: " + String(string_buffer));
      }
      File1.close();
    }
    return answer;
}

Problem only occurs when i use two serial communications, one is interacting with SIM800L module and other is with the serial monitor. Does new line and carriage return has something to do with it? Is it a problem of buffer? or is SIM800L writing that unwanted character on my serial monitor?

Problem occurs in the loop of checking File.available() and File.read(). It starts getting unwanted characters and File.available counter resets the file size and never decrements then.

I observed one more thing. I made one separate program in which i just initialize the modem and do not send anything and just check the operation of file read and print. It still gives an error. But in the same program if i skip modem initialization, it reads and prints file data flawlessly.