-1

I am working on a project using pro mini 8MHz/3.3v and SIM7100, I want to know how can I used AT+CFTRANTX command. I am try to read file from EFS and write to SD card via Serial port. I have get some data in SD but is junk.

My board is Arduino Pro Mini (ATMega 328) 8MHz/3.3 V datasheet (DEV-11114) and Modem is home-made board with SIM7100 module, already test board and module work with all functions without any problem. I’ve added a schematic of the board to the question.

Here is SIM7100 Schematic enter image description here

Here is SD Module, Pro Mini and SIM7100 pin layout enter image description here

c:\data2.txt is: A1 to F0

A1A2A3A4A5A6A7A8A9A0B1B2B3B4B5B6B7B8B9B0C1C2C3C4C5C6C7C8C9C0D1D2D3D4D5D6D7D8D9D0E1E2E3E4E5E6E7E8E9E0F1F2F3F4F5F6F7F8F9F0

Any help would be appropriated.

The code that I am using, I tried it with every possible baud rate:

#include <SPI.h>
#include <SD.h>
#include <SoftwareSerial.h>
SoftwareSerial simSerial(7, 6);
File myFile;

void setup() {
  Serial.begin(9600);
  while (!Serial) {
    ;
  }

  simSerial.begin(9600);
  Serial.print("\nInitializing SD card...");

  if (!SD.begin(10)) {
    Serial.println("\nInitialization failed!");
    while (1);
  }
  Serial.println("\nInitialization done.");
  delay(8000); //For booting SIM7100
  if (SD.exists("1.TXT")) SD.remove("1.TXT");

  myFile = SD.open("1.txt", FILE_WRITE);
  if (myFile) {
    simSerial.println("AT+CFTRANTX=\"c:/data.txt\"");
    while (simSerial.available() > 0) {
      byte voc = simSerial.read();
      myFile.write(voc);
    }
    myFile.close();
    // Serial.println("\nClose done.");
  } else {
    // Serial.println("Error opening 1.txt");
  }

  // re-open the file for reading:
  myFile = SD.open("1.txt");
  if (myFile) {
    Serial.println("1.txt:");
    while (myFile.available()) {
      Serial.print(myFile.read());
    }
    myFile.close();
    Serial.println("\nReading SD Card done.");
  } else {
    Serial.println("Error opening 1.txt");
  }

}

void loop() {

}

Here is test sketch for software & hardware serial.

SoftwareSerial mySerial(7,6); // RX, TX

void setup()
{
  Serial.begin(9600);
  while (!Serial) {
    ;
  }
  Serial.println("Hardware Serial port!");
  mySerial.begin(9600);
  mySerial.println("AT+CFTRANTX=\"c:/data.txt\"");
}

void loop() // run over and over
{
  if (mySerial.available())
    Serial.write(mySerial.read());
  if (Serial.available())
    mySerial.write(Serial.read());
}
2
  • Please attach a description/diagram what is attached where. And is the SD-card-reader part of a Sim7100 shield or extra. If shield which make and type. if extra partswhich parts. And how do you want to write to C:/data.txt on the PC? Make a problem statement what you want to do in logical steps Apr 29, 2020 at 14:19
  • The "data.txt" coming to EFS via ftp from server, and i want to send this file to SD-card. Apr 29, 2020 at 15:03

2 Answers 2

0

When having trouble in getting started with a modem, it's usually best to connect to the modem in "interactive mode", to verify that you're sending the right commands and getting the right responses.

Have you made sure that your modem/module's UART is at the right logic level to interface directly with your Pro Mini? How about the supply voltage? (Post a link to the product). If you're done with all that, then connect only the modem to the Pro Mini:

5V/3.3V -> Vcc (depending on the module's supply voltage)
D6 -> Modem TX
D7 -> Modem RX
Gnd -> Gnd

Then, upload the following to your Pro Mini:

#include <SoftwareSerial.h>

SoftwareSerial fserial(6, 7);

void setup(void)
{
    Serial.begin(57600);
    // I assume this is the default for your modem
    fserial.begin(115200);
    Serial.println("Starting.");
}

void loop(void)
{
    while (fserial.available())
        Serial.write(fserial.read());
    while (Serial.available())
        fserial.write(Serial.read());
}

This should basically transfer everything you send from your Serial Monitor to the modem, and in the reverse, transfer everything the modem sends to your Serial Monitor.

After uploading the sketch, in the Serial Monitor, set the Line Ending at the bottom to Carriage Return. Then you can first send the simple AT and should receive OK from the modem, to confirm that your setup works. Then to test your file reading code, send your command AT+CFTRANTX="c:/data.txt" and see what you get.

If you can confirm this works, writing code to do this automatically should then be much clearer. Or at the very least, you'll have ruled out a whole bunch of possible problems.

(Note: the Arduino may not work reliably with 115200 baud on Software Serial. So you may want to change the modem's baud rate quickly with AT+IPREX=9600. And then modify your sketch accordingly and re-upload.)

4
  • @AliMorawej What baud rate do you see when you enter AT+IPR?? Does your command AT+CFTRANTX work from the serial monitor? May 11, 2020 at 22:45
  • @AliMorawej What did you modify exactly? The baud rate? May 13, 2020 at 0:46
  • @AliMorawej So you can now read the data.txt using this test sketch to send the command? May 13, 2020 at 22:06
  • Yes, read on SIM7100 the AT command without any problem, but when I write it to SD is missed up the data, write data A1A2A3...F9F0, and get on SD something like 000000000062480198616224 change data type char and byte nothing get better ... May 16, 2020 at 16:28
0

The Manual v1.02 of Sim7100 with all the commands can be downloaded here
Here is code to test it compiled for UNO without warnings and errors: Please test it and give feedback (read the comments to get the flow of code) Test with the RX/TX of the Sim7100 to pins 4/5 (Software Serial and the Sim7100 to baud rate 9600):

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

#include <SoftwareSerial.h>

#define SD_ChipSelectPin 10

SoftwareSerial simSerial(5, 6); // RX, TX to TX RX of the SIM7100 module
//#define simSerial Serial
char receiveArray[256] = {'\0'};
void readSerialPort(uint8_t);
uint8_t counter = 0;


void setup() {
   Serial.begin(57600);
    while (!Serial) {
     ;
    }
  simSerial.begin(9600); // using HW Serial on a Pro Mini
  while (!simSerial) {
    ;
  }

  simSerial.println("AT+IPR=9600"); // set sim7100 to same serial speed
  delay(1000);
  simSerial.flush();   // Flush buffer

  SD.begin(SD_ChipSelectPin);
  if (!SD.begin(SD_ChipSelectPin)) {
    //Serial.println("Error opening SD-card");
    return;
  }
  delay(1000);
  if (SD.exists("1.TXT")) SD.remove("1.TXT");
  delay(1000);
}

void loop() {

  if (counter < 3) {
    File saveFile = SD.open("1.TXT", FILE_WRITE);
    if (saveFile) {
      // This has to be the Serial the SIM7100 is attached to
      simSerial.println("AT+CFTRANTX=\"c:/data.txt\"\r");
      while (!simSerial.available()) {} // wait for data to arrive


        readSerialPort(0);

      saveFile.close();

      // Serial.println("Success creating file");
    } else {
      // Serial.println("Error creating file");
    }
    counter++;
  }
}



/* For a first test we print everything to 1.txt -
  there will be "garbagge" as the AT response in it -
  we can "clean" in a later  by using the intermediate array or the counter */
void readSerialPort(uint8_t startIndex = 0) {
  uint16_t i = 0;   // counter and we want later to filter the first X chars
  while (simSerial.available() > 0) {
    char inChar = simSerial.read();
    if (i >= startIndex) { // if we want to filter the first 16 chars it would be i>=16 (as it starts with 0)
      if (inChar == '\n') {
        receiveArray[i] = '\0'; // terminate the array
        return;
      }
      if (inChar != '\r') {
        receiveArray[i] = inChar;
        i++;
      }
    }
  }
}
7
  • The code waits now for the modem to respond May 2, 2020 at 23:11
  • Tried the code is return blank SD Card. May 4, 2020 at 19:06
  • I have rewiring my board and change my data file as above and test the way @ TisteAndii guide me in code above, I got right data in Serial with AT+CFTRANTX="c:/data.txt, but get junk like 000000000062480198616224 on SD Card. My hardware setup and wiring okay now, maybe i help again get he right format on SD Card. May 15, 2020 at 18:42
  • Can you post the last working code in your question? Of course I'll help you May 15, 2020 at 20:08
  • 1
    I done as you said, but nothing change and my SD Crad is shows empty 1.txt. May 20, 2020 at 15:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.