Page 1 of 1

FATFS Write fails when GSM module present

Posted: Tue Apr 23, 2024 9:50 am
by antonjung
I am using an ESP32 with a connected GSM (SIM800L) module.
I use FATFS to manage the on board files.
When the GSM unit is not connected it can read and write data without a problem
When the GSM unit is connected it reads but the write does not happen. There are no error codes returned but no data is written.
Here is a simple sketch to illustrate the problem.
  1. #include <FFat.h>
  2.  
  3. void setup() {
  4.    Serial.begin(115200);
  5.    if (!FFat.begin(true)) {  //if mount fails filesystem is reformatted (optional, default false)
  6.       Serial.println("Mount failed");
  7.       return;
  8.    }
  9.    Serial.println("File contents before write:");
  10.    File file = FFat.open("/testfile.txt");
  11.    if (!file) {
  12.       Serial.println("read open fail");
  13.       return;
  14.    }
  15.    while(file.available()){
  16.       Serial.write(file.read());
  17.    }
  18.    file.close();
  19.    Serial.println ("write data to file");
  20.    file = FFat.open("/testfile.txt",FILE_APPEND);
  21.    if (!file) {
  22.       Serial.println("error creating file");
  23.       return;
  24.    }
  25.    if (file.print("TEST\r\n")) {
  26.       Serial.println("write ok");
  27.    } else {
  28.       Serial.println("write failed");
  29.    }
  30.    file.close();
  31.    file = FFat.open("/testfile.txt");
  32.    if (!file) {
  33.       Serial.println("read open fail");
  34.       return;
  35.    }
  36.    Serial.println("File contents after write:");
  37.    while(file.available()){
  38.       Serial.write(file.read());
  39.    }
  40.    file.close();
  41. }
  42. void loop() {}
When I run this without the GSM module connected I get the following:-

10:41:57.651 -> File contents before write:
10:41:57.651 -> TEST
10:41:57.651 -> write data to file
10:41:57.651 -> write ok
10:41:57.745 -> File contents after write:
10:41:57.745 -> TEST
10:41:57.745 -> TEST

And with the GSM module connected I get this:-


10:45:28.210 -> File contents before write:
10:45:28.210 -> TEST
10:45:28.210 -> TEST
10:45:28.210 -> write data to file
10:45:28.210 -> write ok
10:45:28.210 -> File contents after write:
10:45:28.210 -> TEST
10:45:28.210 -> TEST

Note the extra line hasn't been added to the file.

It may be of interest that prior to using FATFS the solution was using LittleFS. The problem there was that when the GSM unit was connected and I attemoted to write to a file I got lots of BAD BLOCK messages. For this reason I switched to FATFS. I no longer get any messages and the app appears tp work ok but as you can see no data is written to the file system.

Re: FATFS Write fails when GSM module present

Posted: Tue Apr 23, 2024 12:36 pm
by MicroController
Power supply issue? GSM modules can draw huge amounts of current.

Re: FATFS Write fails when GSM module present

Posted: Tue Apr 23, 2024 1:51 pm
by antonjung
Possibly, however the unit is being powered by a separate power supply. The input voltage is 11+

Re: FATFS Write fails when GSM module present

Posted: Tue Apr 23, 2024 2:39 pm
by antonjung
I'm not sure if this might also be a clue, but when I try to upload sketches it will only work if the GSM module is not connected.
When it is connected I get the following message :- A fatal error occurred: MD5 of file does not match data in flash!

Re: FATFS Write fails when GSM module present

Posted: Wed Apr 24, 2024 12:50 am
by ESP_Sprite
Anything connected to GPIO12? In general, what pins is the GSM module connected to?

Re: FATFS Write fails when GSM module present

Posted: Wed Apr 24, 2024 8:36 am
by antonjung
The pin set up is as follows :-

#define SIM800_RX_PIN 13
#define SIM800_TX_PIN 12
#define SIM800_RST_PIN 14

Re: FATFS Write fails when GSM module present

Posted: Thu Apr 25, 2024 1:58 am
by ESP_Sprite
Pin 12 is a bootstrap pin that sets the flash voltage; your GSM module is probably pulling that to the wrong level. You can either move that pin or use espefuse.py to force vdd_sio to 3.3V

Re: FATFS Write fails when GSM module present

Posted: Mon Apr 29, 2024 10:57 am
by antonjung
Change TX_PIN from 12 to 15 and that seems to have done the trick.
Thanks for you help