STM32 F407VET6 SIM800C V2

Post here all questions related to STM32 core if you can't find a relevant section!
Orion1398
Posts: 15
Joined: Tue May 04, 2021 5:28 pm
Answers: 2

STM32 F407VET6 SIM800C V2

Post by Orion1398 »

Hi!
I have some problem with GSM SIM800C V2.
I don't know why but STM didn't send any data.
GSM work correctly (I check it using Arduino Duo. I call and everything works fine)
GPS and other stuff works fine.
Maybe some one can help me?

Core https://github.com/stm32duino/wiki/wiki/Getting-Started

The callnumber() function works fine.
I tested them on an Arduino Uno


The code I use.

Code: Select all

/*
    Board pinout what I use
    https://os.mbed.com/media/uploads/hudakz/stm32f407vet6_right01.png
    https://os.mbed.com/media/uploads/hudakz/stm32f407vet6_left02.png
    https://os.mbed.com/media/uploads/hudakz/stm32f407vet6_st-link03.png
    I found Original Schematic STM32F407VET6
    https://stm32-base.org/assets/pdf/boards/original-schematic-STM32F407VET6-STM32_F4VE_V2.0.pdf
*/

//===========================|Library Block|==============================//
#include "Adafruit_GFX.h" // Graphics processing library 
#include "Adafruit_ILI9341.h" // Software drivers for ILI9341 displays 
#include "Adafruit_Sensor.h" // Adafruit unified sensor library, which provides a common 'type' for sensor data.
#include "Adafruit_BME280.h" // Adafruit library for BME280 sensor
#include "TinyGPS++.h" // Arduino library for parsing NMEA data streams provided by GPS modules.
#include "QMC5883LCompass.h" // Arduino library for QMC5883L sensor
#include "SoftwareSerial.h" //This library allow serial communication on other digital pins, using software to replicate the functionality 
#include "Wire.h" //This library allows you to communicate with I2C / TWI devices.
#include "SPI.h" //This library allows communicate with SPI devices, with the Arduino as the master device.
#include "Keypad.h" // Library for using matrix style keypads with the Arduino


//===========================|QMC5883L Block|==============================//
QMC5883LCompass compass; // I2C
int a = 0; //Azimuth
int b = 0; //Bearing
char myArray[3] = {0, 0, 0}; // Char Direction - N E W S
//For screen overwrite
int oldAzimuth = 0;
int oldBearing = 0;
char oldMyArray[3] = {0, 0, 0};


//===========================|BME280 Block|==============================//
#define SEALEVELPRESSURE_HPA (1015.92)
Adafruit_BME280 bme; // I2C
int Temperature = 0;
int Pressure = 0;
int Altitude = 0;
int Humidity = 0;
//For screen overwrite
int oldTemperature = 0;
int oldPressure = 0;
int oldAltitude = 0;
int oldHumidity = 0;


//===========================|TFT LCD Block|==============================//
#define TFT_DC PD5 // D/C display output connection pin 
#define TFT_CS PD7 // CS display pin connection pin 
#define TFT_RST -1 // RESET  
//#define TFT_RST PA3 - RESE connection pin if use button res
#define TFT_MISO PB14 // SDO display output connection pin (MISO) 
#define TFT_MOSI PB15 // SDI display output connection pin (MOSI) 
#define TFT_CLK PB13 // SCK display output connection pin 
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);


//===========================|GPS NEO 7 M Block|==============================//
static const int GPS_RX = PA7, GPS_TX = PA6; // Soft serial connection pins
static const uint32_t GPSBaud = 9600; // Data transfer rate in bit / s (baud)
TinyGPSPlus gps;// The TinyGPS++ object
SoftwareSerial ss(GPS_RX, GPS_TX);  // The serial connection to the GPS device
float locLAT = 0; // Latitude
float locLNG = 0; //Long
int dateMONTH = 0;
int dateDAY = 0;
int dateYEAR = 0;
int timeHOUR = 0;
int timeMINUTE = 0;
int timeSECOND = 0;
bool errL = false; //Location Error
bool errD = false; //Data Error
bool errT = false; //Time Error


//===========================|GSM SIM800C V2 Block|==============================//
static const int GSM_RX = PA10, GSM_TX = PA9; // Soft serial connection pins
static const uint32_t GSMBaud = 9600; // Data transfer rate in bit / s (baud)
SoftwareSerial SIM800(GSM_RX, GSM_TX); // The serial connection to the GSM device
int _timeout;
String _buffer; // For save and read from Serial (for test Arduino)
String number = "+380935239435";
String SMS = "Test measage";

//===========================|Keypad Block|==============================//
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {PE7, PE8, PE9, PE10}; //Connect to the row pinouts of the keypad
byte colPins[COLS] = {PE11, PE12, PE13, PE14}; //Connect to the column pinouts of the keypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); //Initialize an instance of class NewKeypad


//===========================|MENU Block|==============================//
static bool initialized; //Menu Loading Flag
//Visibility Section
int seeFuncMenu = 0;        // 1 - BME280, 2 - QMC, 3 - GPS, 4 - GSM
int butState = 0; // 0 - MainMenu 1 - A Menu, 2 - B Menu, 3 - C Menu, 4 - D Menu
bool button = true; // Ture/False - Unclicked/Clicked


//===========================|SETUP Block|==============================//
void setup()
{
  //Initiates a serial connection and sets the data transfer rate in bit / s (baud)
  Serial.begin(9600);

  //GSM
  _buffer.reserve(50);
  SIM800.begin(GSMBaud); //Initialize GSM
  SIM800.println("AT");

  //GPS
  ss.begin(GPSBaud); //Initialize GPS

  //BME280
  bme.begin(0x76); //Initialize BME280

  //QMC
  Wire.begin(); //Initialize
  compass.setCalibration(-680, 1625, -1890, 1928, -4123, 0); // Calibration data
  compass.init(); //Initialize QMC

  //Logo
  tft.begin(); //Initialize TFT
  tft.setRotation(0); //Screen rotation
  tft.fillScreen(0x0101); //The fillScreen function changes the screen color to 0x0101
  tft.fillRect(0, 0, 240, 25, ILI9341_RED); //The fillRect function draws a filled rectangle
  tft.setTextColor(ILI9341_WHITE); //Sets the color of the text
  tft.setTextSize(2); //Set the text size
  tft.setCursor(72, 5); //Set the cursor position
  tft.print("Testing"); //Write something on screen

  tft.setTextColor(ILI9341_BLACK);
  tft.setTextSize(2);
  //tft.fillRoundRect(10, 50, 220, 50, 4 , ILI9341_YELLOW);
  tft.fillRoundRect(10, 50, 220, 230, 4 , ILI9341_YELLOW);
  tft.setCursor(20, 120);
  tft.print("My Course Project");

  tft.setTextColor(ILI9341_GREEN);
  tft.fillRoundRect(0, 300, 240, 30, 10 , ILI9341_ORANGE);
  tft.setCursor(100, 301);
  tft.print("STM");

  //Keypad
  customKeypad.setHoldTime(500);
  customKeypad.setDebounceTime(250);
  delay(2000);
}


//===========================|LOOP Block|==============================//
void loop()
{
  if (!initialized)
  {
    initialized = true;
    drawMenu();
  }

  char customKey = customKeypad.getKey(); // What button we press

  //If we are in some Menu
  if (seeFuncMenu == 1)
  {
    funcBME280();
  }
  else if (seeFuncMenu == 2)
  {
    funcQMC5883L();
  }
  else if (seeFuncMenu == 3)
  {
    //gps.encode(ss.read());
    //funcGPSNEO7M();

    while (ss.available() > 0)
      if (gps.encode(ss.read()))
        funcGPSNEO7M();

    if (millis() > 5000 && gps.charsProcessed() < 10)
    {
      tft.setTextColor(ILI9341_RED);
      tft.setTextSize(1);
      tft.setCursor(10, 35);
      tft.print(F("GPS NEO-7M"));
      tft.setCursor(10, 55);
      tft.print(F("No GPS detected: check wiring."));
      //while (true);
    }

  }
  else if (seeFuncMenu == 4)
  {

  }

  //Menu chose
  switch (customKey)
  {
    case 'A':
      menuBME280();
      break;
    case 'B':
      if ( butState == 1)
      {
        tft.fillRect(0, 30, 240, 262, 0x0101);
        tft.setTextColor(ILI9341_WHITE, 0x0101);
        tft.setTextSize(2);
        tft.setCursor(10,  40);
        tft.print("BME280 - SubMenu 1");
        seeFuncMenu = 0;
      }
      else if ( butState == 2)
      {
        tft.fillRect(0, 30, 240, 262, 0x0101);
        tft.setTextColor(ILI9341_WHITE, 0x0101);
        tft.setTextSize(2);
        tft.setCursor(10,  40);
        tft.print("QMC - SubMenu 1");
        seeFuncMenu = 0;
      }
      else if ( butState == 3)
      {
        tft.fillRect(0, 30, 240, 262, 0x0101);
        tft.setTextColor(ILI9341_WHITE, 0x0101);
        tft.setTextSize(2);
        tft.setCursor(10,  40);
        tft.print("GPS - SubMenu 1");
        seeFuncMenu = 0;
      } else if ( butState == 4)
      {
        tft.fillRect(0, 30, 240, 262, 0x0101);
        tft.setTextColor(ILI9341_WHITE, 0x0101);
        tft.setTextSize(2);
        tft.setCursor(10,  40);
        tft.print("GSM - SubMenu 1");
        seeFuncMenu = 0;
      } else
      {
        menuQMC();
      }
      break;
    case 'C':
      if ( butState == 1)
      {
        tft.fillRect(0, 30, 240, 262, 0x0101);
        tft.setTextColor(ILI9341_WHITE, 0x0101);
        tft.setTextSize(2);
        tft.setCursor(10,  40);
        tft.print("BME280 - SubMenu 2");
        seeFuncMenu = 0;
      }
      else if ( butState == 2)
      {
        tft.fillRect(0, 30, 240, 262, 0x0101);
        tft.setTextColor(ILI9341_WHITE, 0x0101);
        tft.setTextSize(2);
        tft.setCursor(10,  40);
        tft.print("QMC - SubMenu 2");
        seeFuncMenu = 0;
      }
      else if ( butState == 3)
      {
        tft.fillRect(0, 30, 240, 262, 0x0101);
        tft.setTextColor(ILI9341_WHITE, 0x0101);
        tft.setTextSize(2);
        tft.setCursor(10,  40);
        tft.print("GPS - SubMenu 2");
        seeFuncMenu = 0;
      }
      else if ( butState == 4)
      {
        tft.fillRect(0, 30, 240, 262, 0x0101);
        tft.setTextColor(ILI9341_WHITE, 0x0101);
        tft.setTextSize(2);
        tft.setCursor(10,  40);
        tft.print("GSM - SubMenu 2");
        seeFuncMenu = 0;
      }
      else
      {
        menuGPSNEO7M();
      }

      break;
    case 'D':
      if ( butState == 1)
      {
        tft.fillRect(0, 30, 240, 262, 0x0101);
        tft.setTextColor(ILI9341_WHITE, 0x0101);
        tft.setTextSize(2);
        tft.setCursor(10,  40);
        tft.print("BME280 - SubMenu 3");
        seeFuncMenu = 0;
      }
      else if ( butState == 2)
      {
        tft.fillRect(0, 30, 240, 262, 0x0101);
        tft.setTextColor(ILI9341_WHITE, 0x0101);
        tft.setTextSize(2);
        tft.setCursor(10,  40);
        tft.print("QMC - SubMenu 3");
        seeFuncMenu = 0;
      }
      else if ( butState == 3)
      {
        tft.fillRect(0, 30, 240, 262, 0x0101);
        tft.setTextColor(ILI9341_WHITE, 0x0101);
        tft.setTextSize(2);
        tft.setCursor(10,  40);
        tft.print("GPS - SubMenu 3");
        seeFuncMenu = 0;
      } else if ( butState == 4)
      {
        tft.fillRect(0, 30, 240, 262, 0x0101);
        tft.setTextColor(ILI9341_WHITE, 0x0101);
        tft.setTextSize(2);
        tft.setCursor(10,  40);
        tft.print("GSM - SubMenu 3");
        seeFuncMenu = 0;
      } else
      {
        menuGSM();
      }
      break;
  }
  delay(1);
}

//======================================================================================//
//===========================|Menu BME280 Block|=======================================//
//====================================================================================//
void menuBME280()
{
  if (button)
  {
    //if we press A button first time
    tft.fillRect(0, 30, 240, 262, 0x0101);
    seeFuncMenu = 1;
    button = false;
    butState = 1;
  }
  else if (!button)
  {
    // if we press A button second time
    seeFuncMenu = 0;
    drawMenu();
    button = true;
    butState = 0;
  }
}

//======================================================================================//
//===========================|Menu QMC5883L Block|=====================================//
//====================================================================================//
void menuQMC()
{
  if (button)
  {
    //if we press B button first time
    tft.fillRect(0, 30, 240, 262, 0x0101);
    seeFuncMenu = 2;
    button = false;
    butState = 2;
  }
}

//======================================================================================//
//===========================|Menu GPS NEO 7 M Block|==================================//
//====================================================================================//
void menuGPSNEO7M()
{
  if (button)
  {
    //if we press C button first time
    tft.fillRect(0, 30, 240, 262, 0x0101);
    seeFuncMenu = 3;
    button = false;
    butState = 3;
  }
}

//======================================================================================//
//===========================|Menu GSM SIM800C V2 Block|===============================//
//====================================================================================//
void menuGSM()
{
  if (button)
  {
    //if we press D button first time
    tft.fillRect(0, 30, 240, 262, 0x0101);
    callNumber();
    seeFuncMenu = 4;
    button = false;
    butState = 4;
  }
}

//======================================================================================//
//===========================|Function BME280 Block|===================================//
//====================================================================================//
void funcBME280()
{
  oldTemperature = Temperature;
  oldPressure = Pressure;
  oldAltitude = Altitude;
  oldHumidity = Humidity;
  Temperature = bme.readTemperature();
  Pressure = bme.readPressure() / 100;
  Altitude = bme.readAltitude(SEALEVELPRESSURE_HPA);
  Humidity = bme.readHumidity();

  if (seeFuncMenu = 1)
  {
    tft.setTextColor(ILI9341_RED, 0x0101);
    tft.setTextSize(2);
    tft.setCursor(10,  40);
    tft.print("BME280");
    tft.setCursor(10,  70);
    tft.print("Temperature:");
    if (Temperature != oldTemperature)
    {
      tft.fillRect(150, 70, 100, 14, 0x0101);
    }
    tft.setCursor(150, 70);
    tft.print(Temperature);
    tft.setCursor(10,  100);
    tft.print("Pressure:");
    if (Pressure != oldPressure)
    {
      tft.fillRect(150, 100, 100, 14, 0x0101);
    }
    tft.setCursor(150, 100);
    tft.print(Pressure);
    tft.setCursor(10,  130);
    tft.print("Altitude:");
    if (Altitude != oldAltitude)
    {
      tft.fillRect(150, 130, 100, 14, 0x0101);
    }
    tft.setCursor(150, 130);
    tft.print(Altitude);
    tft.setCursor(10,  160);
    tft.print("Humidity:");
    if (Humidity != oldHumidity)
    {
      tft.fillRect(150, 160, 100, 14, 0x0101);
    }
    tft.setCursor(150, 160);
    tft.print(Humidity);
  }
}

//======================================================================================//
//===========================|Function QMC5883L Block|=================================//
//====================================================================================//
void funcQMC5883L()
{
  oldAzimuth = a;
  oldBearing = b;
  oldMyArray[1] = myArray[1];
  oldMyArray[2] = myArray[2];
  oldMyArray[3] = myArray[3];
  compass.read(); //Get data from compass
  a = compass.getAzimuth(); //Read azimuth
  b = compass.getBearing(a); //Read Bearing (sent azimuth)
  compass.getDirection(myArray, a); //Read direction (write on array, sent azimuth)

  if (seeFuncMenu = 2)
  {
    tft.setTextColor(ILI9341_GREEN, 0x0101);
    tft.setTextSize(2);
    tft.setCursor(10,  40);
    tft.print("QMC");
    tft.setCursor(10,  70);
    tft.print("Azimuth:");
    if (oldAzimuth != a)
    {
      tft.fillRect(150, 70, 100, 14, 0x0101);
    }
    tft.setCursor(150, 70);
    tft.print(a);
    tft.setCursor(10,  100);
    tft.print("Bearing:");
    if (oldBearing != b)
    {
      tft.fillRect(150, 100, 100, 14, 0x0101);
    }
    tft.setCursor(150, 100);
    tft.print(b);
    tft.setCursor(10,  130);
    tft.print("Direction:");
    if ( oldMyArray[1] != myArray[1] || oldMyArray[2] != myArray[2] || oldMyArray[3] != myArray[3] )
    {
      tft.fillRect(150, 130, 100, 14, 0x0101);
    }
    tft.setCursor(150, 130);
    tft.write(myArray);
    tft.setCursor(10, 220);
    tft.fillTriangle(120, 160, 60, 290, 180, 290, ILI9341_GREEN); //Print triangle
  }
}

//======================================================================================//
//===========================|Function GPS NEO 7 M Block|==============================//
//====================================================================================//
void  funcGPSNEO7M()
{
  locLAT = gps.location.lat();
  locLNG = gps.location.lng();
  dateMONTH = gps.date.month();
  dateDAY = gps.date.day();
  dateYEAR = gps.date.year();
  timeHOUR = gps.time.hour();
  timeMINUTE = gps.time.minute();
  timeSECOND = gps.time.second();

  if (seeFuncMenu = 3)
  {
    //Menu GPS
    tft.setTextColor(ILI9341_WHITE, 0x0101);
    tft.setTextSize(1);
    tft.setCursor(10, 35);
    tft.print("GPS NEO-7M");
    tft.setCursor(10, 45);
    tft.print("LOCATION");
    tft.setCursor(10, 65);
    tft.print("DATE");
    tft.setCursor(10, 85);
    tft.print("TIME UTC");
  }
  //Location LAT - LNG
  if (gps.location.isValid())
  {
    if (errL)
    {
      if (seeFuncMenu = 3)
      {
        tft.fillRect(10, 55, 260, 7, 0x0101);
      }
    }
    if (seeFuncMenu = 3)
    {
      tft.setTextColor(ILI9341_WHITE, 0x0101);
      tft.setTextSize(1);
      tft.setCursor(10, 55);
      tft.print("LAT: ");
      tft.fillRect(35, 55, 60, 7, 0x0101);
      tft.setCursor(35, 55);
      tft.print(locLAT);
      tft.setCursor(145, 55);
      tft.print("LGN: ");
      tft.fillRect(170, 55, 60, 7, 0x0101);
      tft.setCursor(170, 55);
      tft.print(locLNG);
    }
  }
  else
  {
    errL = true;
    if (seeFuncMenu = 3)
    {
      tft.fillRect(10, 55, 260, 7, 0x0101);
      tft.setTextColor(ILI9341_WHITE, 0x0101);
      tft.setTextSize(1);
      tft.setCursor(10, 55);
      tft.print("INVALID LOCATION");
    }
  }
  //DATE
  if (gps.date.isValid())
  {
    if (errD)
    {
      if (seeFuncMenu = 3)
      {
        tft.fillRect(10, 75, 260, 7, 0x0101);
      }
    }
    if (seeFuncMenu = 3)
    {
      tft.setTextColor(ILI9341_WHITE, 0x0101);
      tft.setTextSize(1);
      tft.setCursor(10, 75);
      tft.print("Month/Day/Year:");
      tft.setCursor(105, 75);
      tft.print(dateMONTH);
      tft.setCursor(110, 75);
      tft.print("/");
      tft.setCursor(115, 75);
      tft.print(dateDAY);
      tft.setCursor(120, 75);
      tft.print("/");
      tft.setCursor(125, 75);
      tft.print(dateYEAR);
    }
  }
  else
  {
    errD = true;
    if (seeFuncMenu = 3)
    {
      tft.fillRect(10, 75, 260, 7, 0x0101);
      tft.setTextColor(ILI9341_WHITE, 0x0101);
      tft.setTextSize(1);
      tft.setCursor(10, 75);
      tft.print("INVALID DATE");
    }
  }
  //TIME
  if (gps.time.isValid())
  {
    if (errT)
    {
      if (seeFuncMenu = 3)
      {
        tft.fillRect(10, 95, 260, 7, 0x0101);
      }

    }
    if (timeHOUR < 10)
    {
      if (seeFuncMenu = 3)
      {
        tft.fillRect(10, 95, 25, 7, 0x0101);
        tft.setTextColor(ILI9341_WHITE, 0x0101);
        tft.setTextSize(1);
        tft.setCursor(10, 95);
        tft.print("0");
        tft.setCursor(16, 95);
        tft.print(timeHOUR);
      }
    }
    else
    {
      if (seeFuncMenu = 3)
      {
        tft.fillRect(10, 95, 25, 7, 0x0101);
        tft.setTextColor(ILI9341_WHITE, 0x0101);
        tft.setTextSize(1);
        tft.setCursor(10, 95);
        tft.print(timeHOUR);
      }
    }
    if (timeMINUTE < 10)
    {
      if (seeFuncMenu = 3)
      {
        tft.fillRect(25, 95, 25, 7, 0x0101);
        tft.setTextColor(ILI9341_WHITE, 0x0101);
        tft.setTextSize(1);
        tft.setCursor(25, 95);
        tft.print("0");
        tft.setCursor(31, 95);
        tft.print(timeMINUTE);
      }
    }
    else
    {
      if (seeFuncMenu = 3)
      {
        tft.fillRect(25, 95, 25, 7, 0x0101);
        tft.setTextColor(ILI9341_WHITE, 0x0101);
        tft.setTextSize(1);
        tft.setCursor(25, 95);
        tft.print(timeMINUTE);
      }
    }
    if (timeSECOND < 10)
    {
      if (seeFuncMenu = 3)
      {
        tft.fillRect(40, 95, 25, 7, 0x0101);
        tft.setTextColor(ILI9341_WHITE, 0x0101);
        tft.setTextSize(1);
        tft.setCursor(40, 95);
        tft.print("0");
        tft.setCursor(46, 95);
        tft.print(timeSECOND);
      }
    }
    else
    {
      if (seeFuncMenu = 3)
      {
        tft.fillRect(40, 95, 25, 7, 0x0101);
        tft.setTextColor(ILI9341_WHITE, 0x0101);
        tft.setTextSize(1);
        tft.setCursor(40, 95);
        tft.print(timeSECOND);
      }
    }
  }
  else
  {
    errT = true;
    if (seeFuncMenu = 3)
    {
      tft.fillRect(10, 95, 260, 7, 0x0101);
      tft.setTextColor(ILI9341_WHITE, 0x0101);
      tft.setTextSize(1);
      tft.setCursor(10, 95);
      tft.print("INVALID TIME");
    }
  }
}

//======================================================================================//
//===========================|Function GSM SIM800C V2 Block|===========================//
//====================================================================================//

void SendMessage()
{
  SIM800.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
  delay(200);
  SIM800.println("AT+CMGS=\"" + number + "\"\r"); //Mobile phone number to send message
  delay(200);
  SIM800.println(SMS);
  delay(100);
  SIM800.println((char)26);// ASCII code of CTRL+Z
  delay(200);
  _buffer = _readSerial();
}

void RecieveMessage()
{
  if (seeFuncMenu = 5)
  {
    tft.setTextColor(ILI9341_WHITE);
    tft.setTextSize(2);
    tft.setCursor(10, 45);
    tft.println("SIM800C Read an SMS");
    tft.setTextSize(1);
    SIM800.println("AT+CMGF=1");
    delay (200);
    SIM800.println("AT+CNMI=1,2,0,0,0"); // AT Command to receive a live SMS
    delay(200);
    tft.println("Unread Message done");
    //Serial.write ("Unread Message done");
  }
}
void callNumber()
{
  if (seeFuncMenu = 4)
  {
    SIM800.print (F("ATD"));
    SIM800.print (number);
    SIM800.print (F(";\r\n"));
    //SIM800.print("ATD+380935239435;");
    _buffer = _readSerial();
    tft.setTextColor(ILI9341_RED);
    tft.setTextSize(2);
    tft.setCursor(30, 100);
    tft.print(_buffer);
  }

}

String _readSerial()
{
  _timeout = 0;
  while  (!SIM800.available() && _timeout < 1000 )
  {
    delay(13);
    _timeout++;
  }
  if (SIM800.available()) {
    return SIM800.readString();
  }
}

void drawMenu()
{
  tft.fillRect(0, 30, 240, 262, 0x0101);
  tft.setTextColor(ILI9341_BLACK);
  tft.setTextSize(3);
  tft.fillRoundRect(10, 50, 220, 50, 6 , ILI9341_YELLOW);
  tft.setCursor(97, 63);
  tft.print("BME");

  tft.fillRoundRect(10, 110, 220, 50, 6 , ILI9341_YELLOW);
  tft.setCursor(97, 123);
  tft.print("QMC");

  tft.fillRoundRect(10, 170, 220, 50, 6 , ILI9341_YELLOW);
  tft.setCursor(97, 183);
  tft.print("GPS");

  tft.fillRoundRect(10, 230, 220, 50, 6 , ILI9341_YELLOW);
  tft.setCursor(97, 243);
  tft.print("GSM");
}


/*
  #define PERIOD1 1000
  uint32_t timer1 = 0;
   if (millis() - timer1 >= PERIOD1)
    {
      somefunc();
      do
      {
        timer1 += PERIOD1;
        if (timer1 < PERIOD1) break;
      }
      while (timer1 < millis() - PERIOD1);
    }
*/
/*

  while (ss.available() > 0)
  if (gps.encode(ss.read()))
    funcGPSNEO7M();

  if (millis() > 5000 && gps.charsProcessed() < 10)
  {
  tft.setTextColor(ILI9341_RED);
  tft.setTextSize(1);
  tft.setCursor(10, 35);
  tft.print(F("GPS NEO-7M"));
  tft.setCursor(10, 55);
  tft.print(F("No GPS detected: check wiring."));
  while (true);
  }

  if (SIM800.available() > 0)
    Serial.write(SIM800.read());
*/
/*
  if (customKey)
  {
    //char waitForKey();
    if (customKey == 'A')
    {
      //SendMessage();
      tft.fillRect(0, 30, 240, 260, 0x0000);
      tft.setTextColor(ILI9341_WHITE);
      tft.setTextSize(2);
      tft.setCursor(10, 45);
      tft.print("SendMessage");
    }
    if (customKey == 'B')
    {
      //RecieveMessage();
      tft.fillRect(0, 30, 240, 260, 0x0000);
      tft.setTextColor(ILI9341_WHITE);
      tft.setTextSize(2);
      tft.setCursor(10, 45);
      tft.print("RecieveMessage");
    }
    if (customKey == 'C')
    {
      //callNumber();
      tft.fillRect(0, 30, 240, 260, 0x0000);
      tft.setTextColor(ILI9341_WHITE);
      tft.setTextSize(2);
      tft.setCursor(10, 45);
      tft.print("callNumber");
    }
  }
*/
by Orion1398 » Sun May 16, 2021 6:59 pm
Hi!
Everything works! :)
I use logic level converter, and try work whit SIM module using 5v logic.

TLL -> 5V
RX 3.3V (STM) -> LLC ->TX 5V (SIM)
TX 3.3V (STM) <- LLC <-RX 5V (SIM)

Most likely, there was a problem with TTL on the SIM module, and correctly work only 5V logic.

Thank you all very much, and I went to make a menu for that thing) :D
Go to full post
User avatar
fpiSTM
Posts: 1745
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: STM32 F407VET6 SIM800C V2

Post by fpiSTM »

Hi
First I advice to test only GSM with the STM32.
Then I know several GSM library uses the software Serial library. STM32 core provide it for compatibilty but often do not work as too much time consuming. Originally this library was developed by Arduino as a "workaround" for mcu with limited USART number.
STM32 provides more UART so I advise to use a real serial using HardwareSerial.

Edit: I can see you used 2 Software Serial so you can be sure this is why it does not work. Your application spent all times to manage those SoftwareSerial instances.
Orion1398
Posts: 15
Joined: Tue May 04, 2021 5:28 pm
Answers: 2

Re: STM32 F407VET6 SIM800C V2

Post by Orion1398 »

fpiSTM wrote: Tue May 11, 2021 9:31 am Hi
First I advice to test only GSM with the STM32.
Then I know several GSM library uses the software Serial library. STM32 core provide it for compatibilty but often do not work as too much time consuming. Originally this library was developed by Arduino as a "workaround" for mcu with limited USART number.
STM32 provides more UART so I advise to use a real serial using HardwareSerial.

Edit: I can see you used 2 Software Serial so you can be sure this is why it does not work. Your application spent all times to manage those SoftwareSerial instances.
I try use a Hardware Serial but probably I do something wrong.
What settings I needs to use in U(S)ART support?
I use Enabled generic 'serial'.

Maybe you or someone can give an example of how to do it right? For GSM module?

Here is pinout and sheme :
https://os.mbed.com/users/hudakz/code/S ... /shortlog/
https://stm32-base.org/assets/pdf/board ... E_V2.0.pdf

I try use Serial 1 and 2 but nothing change.
And Thanks for Answers!
User avatar
fpiSTM
Posts: 1745
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: STM32 F407VET6 SIM800C V2

Post by fpiSTM »

First the link to the wiki: https://github.com/stm32duino/wiki/wiki ... wareserial

For Serial menu, basically your sketch uses the default Serial instance which is mapped to one U(S)ART.
Seems you used the BLACK F407VE, the default Serial is PA10/PA9 which use UART1 so the Serial instance is mapped to Serial1.

Now you need to define other Serialx instance for the GSM and the GPS.

Based on your sketch you used for the GSM:

Code: Select all

static const int GSM_RX = PA10, GSM_TX = PA9; // Soft serial connection pins
But this is the same pins than the default Serial so you can use: PA3/PA2 which are linked to USART2

Code: Select all

- static const int GSM_RX = PA10, GSM_TX = PA9; // Soft serial connection pins
+ static const int GSM_RX = PA3, GPS_TX = PA2; // Hardwareserial connection pins
and

Code: Select all

- SoftwareSerial SIM800(GSM_RX, GSM_TX); // The serial connection to the GSM device
+ HardwareSerial SIM800(GSM_RX, GSM_TX); // The serial connection to the GSM device
For the GPS:

Code: Select all

static const int GPS_RX = PA7, GPS_TX = PA6; // Soft serial connection pins
But those pins have no U(S)ART capabilities on the F407VE and they are connected to LED's D2 and D3.
You can PB11/PB10 linked to USART3.

Code: Select all

- static const int GPS_RX = PA7, GPS_TX = PA6; // Soft serial connection pins
+ static const int GPS_RX = PB11, GPS_TX = PB10; // Hardwareserial connection pins

Code: Select all

- SoftwareSerial ss(GPS_RX, GPS_TX);  // The serial connection to the GPS device
+ HardwareSerial ss(GPS_RX, GPS_TX);  // The serial connection to the GPS device
Orion1398
Posts: 15
Joined: Tue May 04, 2021 5:28 pm
Answers: 2

Re: STM32 F407VET6 SIM800C V2

Post by Orion1398 »

fpiSTM wrote: Wed May 12, 2021 8:17 am First the link to the wiki: https://github.com/stm32duino/wiki/wiki ... wareserial

For Serial menu, basically your sketch uses the default Serial instance which is mapped to one U(S)ART.
Seems you used the BLACK F407VE, the default Serial is PA10/PA9 which use UART1 so the Serial instance is mapped to Serial1.

Now you need to define other Serialx instance for the GSM and the GPS.

Based on your sketch you used for the GSM:

Code: Select all

static const int GSM_RX = PA10, GSM_TX = PA9; // Soft serial connection pins
But this is the same pins than the default Serial so you can use: PA3/PA2 which are linked to USART2

Code: Select all

- static const int GSM_RX = PA10, GSM_TX = PA9; // Soft serial connection pins
+ static const int GSM_RX = PA3, GPS_TX = PA2; // Hardwareserial connection pins
and

Code: Select all

- SoftwareSerial SIM800(GSM_RX, GSM_TX); // The serial connection to the GSM device
+ HardwareSerial SIM800(GSM_RX, GSM_TX); // The serial connection to the GSM device
For the GPS:

Code: Select all

static const int GPS_RX = PA7, GPS_TX = PA6; // Soft serial connection pins
But those pins have no U(S)ART capabilities on the F407VE and they are connected to LED's D2 and D3.
You can PB11/PB10 linked to USART3.

Code: Select all

- static const int GPS_RX = PA7, GPS_TX = PA6; // Soft serial connection pins
+ static const int GPS_RX = PB11, GPS_TX = PB10; // Hardwareserial connection pins

Code: Select all

- SoftwareSerial ss(GPS_RX, GPS_TX);  // The serial connection to the GPS device
+ HardwareSerial ss(GPS_RX, GPS_TX);  // The serial connection to the GPS device
Thank you very much.
I use hardware serial, as you said, everything started to work faster) but GSM still does not respond to commands.
When I call to gsm I hear the music, I try to send an ATA command to pick up the phone, but nothing change.
Tried to use Serial6 but to no avail.

I use this function to call.

Code: Select all

void callNumber()
{
  if (seeFuncMenu = 4)
  {
    SIM800.print (F("ATD"));
    SIM800.print (number);
    SIM800.print (F(";\r\n"));
    _buffer = _readSerial();
    tft.setTextColor(ILI9341_RED);
    tft.setTextSize(2);
    tft.setCursor(30, 100);
    tft.print(_buffer);
  }
}

String _readSerial()
{
  _timeout = 0;
  while  (!SIM800.available() && _timeout < 1000 )
  {
    delay(13);
    _timeout++;
  }
  if (SIM800.available()) {
    return SIM800.readString();
  }
}
And this is result what I get. :?:
https://drive.google.com/file/d/1gnD4LU ... sp=sharing

On Arduino this function work fine. What I do wrong? :|
I use battery for GSM. I tested them using Arduino and everything works fine.
And thank you again !
User avatar
fpiSTM
Posts: 1745
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: STM32 F407VET6 SIM800C V2

Post by fpiSTM »

Fine to see some stuff work.
For the modem issue, I would try the modem alone first.
The fact it works on Uno can be related to the voltage level. Uno is 5V while STM32 is 3.3V even if several GPIO pin are 5V tolerant.

Do you have a link to the module you used ?
or maybe a pins conflict a schematics of your wiring would be helpful too.
Orion1398
Posts: 15
Joined: Tue May 04, 2021 5:28 pm
Answers: 2

Re: STM32 F407VET6 SIM800C V2

Post by Orion1398 »

fpiSTM wrote: Wed May 12, 2021 1:31 pm Fine to see some stuff work.
For the modem issue, I would try the modem alone first.
The fact it works on Uno can be related to the voltage level. Uno is 5V while STM32 is 3.3V even if several GPIO pin are 5V tolerant.

Do you have a link to the module you used ?
or maybe a pins conflict a schematics of your wiring would be helpful too.
Datasheet what I found.
https://www.elecrow.com/download/SIM800 ... _V1.02.pdf
But I Cant find there V_TTL pin

I try use 3.3V to 5V Logic Level Converter and put to V_TTL 5V (now apply a 3.3 V іf use arduino 5V )


This is what it looks like
Image
Image
Image
Last edited by Orion1398 on Wed May 12, 2021 2:52 pm, edited 3 times in total.
User avatar
fpiSTM
Posts: 1745
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: STM32 F407VET6 SIM800C V2

Post by fpiSTM »

Well based on the datasheet it seems Serial interface depending of voltage should be adapted:
SIM800C_Serial.png
SIM800C_Serial.png (60 KiB) Viewed 4849 times
One other option you should check is the flow control.
User avatar
fpiSTM
Posts: 1745
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: STM32 F407VET6 SIM800C V2

Post by fpiSTM »

Seems this one:
https://www.amazon.com/Comimark-SIM800C ... B07WXPTW26

So 3.3V should be compatible.
Maybe look around the flow control. As stated before I would test the SIM800 alone.
Orion1398
Posts: 15
Joined: Tue May 04, 2021 5:28 pm
Answers: 2

Re: STM32 F407VET6 SIM800C V2

Post by Orion1398 »

fpiSTM wrote: Wed May 12, 2021 3:12 pm Seems this one:
https://www.amazon.com/Comimark-SIM800C ... B07WXPTW26

So 3.3V should be compatible.
Maybe look around the flow control. As stated before I would test the SIM800 alone.
Ok, thanks.
I connect to STM only SIM Module and test.
Post Reply

Return to “General discussion”