FATFS Write fails when GSM module present

antonjung
Posts: 9
Joined: Tue Apr 23, 2024 8:59 am

FATFS Write fails when GSM module present

Postby antonjung » Tue Apr 23, 2024 9:50 am

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.

MicroController
Posts: 1724
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: FATFS Write fails when GSM module present

Postby MicroController » Tue Apr 23, 2024 12:36 pm

Power supply issue? GSM modules can draw huge amounts of current.

antonjung
Posts: 9
Joined: Tue Apr 23, 2024 8:59 am

Re: FATFS Write fails when GSM module present

Postby antonjung » Tue Apr 23, 2024 1:51 pm

Possibly, however the unit is being powered by a separate power supply. The input voltage is 11+

antonjung
Posts: 9
Joined: Tue Apr 23, 2024 8:59 am

Re: FATFS Write fails when GSM module present

Postby antonjung » Tue Apr 23, 2024 2:39 pm

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!

ESP_Sprite
Posts: 9757
Joined: Thu Nov 26, 2015 4:08 am

Re: FATFS Write fails when GSM module present

Postby ESP_Sprite » Wed Apr 24, 2024 12:50 am

Anything connected to GPIO12? In general, what pins is the GSM module connected to?

antonjung
Posts: 9
Joined: Tue Apr 23, 2024 8:59 am

Re: FATFS Write fails when GSM module present

Postby antonjung » Wed Apr 24, 2024 8:36 am

The pin set up is as follows :-

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

ESP_Sprite
Posts: 9757
Joined: Thu Nov 26, 2015 4:08 am

Re: FATFS Write fails when GSM module present

Postby ESP_Sprite » Thu Apr 25, 2024 1:58 am

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

antonjung
Posts: 9
Joined: Tue Apr 23, 2024 8:59 am

Re: FATFS Write fails when GSM module present

Postby antonjung » Mon Apr 29, 2024 10:57 am

Change TX_PIN from 12 to 15 and that seems to have done the trick.
Thanks for you help

Who is online

Users browsing this forum: No registered users and 186 guests