[Solved] Multiple serial port at the same time doesn't work

Post here all questions related to STM32 core if you can't find a relevant section!
Post Reply
dinihuygens
Posts: 13
Joined: Thu Dec 17, 2020 9:20 am
Answers: 1

[Solved] Multiple serial port at the same time doesn't work

Post by dinihuygens »

I'm doing a little project using STM32F103C8 for a GPS tracker system. I'm using GPS Neo-6m and SIM800L to send GPS value to the user phone number every 5 minutes. For your information, I'm using this core: [https://github.com/stm32duino/Arduino_Core_STM32] and my development environment is Arduino IDE. I have been successfully uploading the program to STM32 without any TTL converter and it works. My upload method is Maple DFU Bootloader 2.0. I'm using Serial2 (PA3, PA2) for GPS and Serial3 (PB11, PB10) for SIM800L, both of them are working fine when I run separately. First, I tried to send a message every 5 minutes and it's working fine. Second, I tried to get the GPS value and it's working too. But when I run it in one program, it doesn't work. When I was trying to run this program in Arduino Uno it's working fine. I have been searching for solutions but none of them work.
I don't know why it doesn't work in STM32? Is there any particular setting to use multiple serial ports in STM32?
Thanks in advance :)

This is my code:

Code: Select all


#include <TinyGPS++.h>
#include <LiquidCrystal_I2C.h>



//sms
char ReceivedSms;
short DHT_OK = -1, GPS_OK = -1;
String DataSms;
int _timeout;
String _buffer;
String number = "+628XXXXX";


LiquidCrystal_I2C lcd(0x27, 20, 4);

HardwareSerial Serial2(PA3, PA2);
HardwareSerial Serial3(PB11, PB10);


// The TinyGPS++ object
TinyGPSPlus gps;

void setup()
{
  Serial2.begin(9600);
  Serial3.begin(9600);
  lcd.init();
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.clear();
  lcd.print("Starting..");
  delay(1000);
  lcd.clear();
  _buffer.reserve(50);

}

void loop()
{
  while (Serial2.available() > 0)
    if (gps.encode(Serial2.read()))
      displayInfo();

  if (millis() > 5000 && gps.charsProcessed() < 10)
  {
    lcd.clear();
    lcd.setCursor(1, 1);
    lcd.print("check wiring");
    delay(3000);
    while (true);
  }
}

void displayInfo()
{

  if (gps.location.isValid())
  {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.println(gps.location.lat(), 6);
    lcd.setCursor(0, 1);
    lcd.println(gps.location.lng(), 6);
    delay(2000);
    String link = "http://www.google.com/maps/place/" + String(gps.location.lat(), 6) + "," + String(gps.location.lng(), 6);
    DataSms = "ALL\nMaps = " + link;  
    
    SendMessage(); 
    delay(1000*60*5);
  }
  else
  {
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("No location");
      delay(2000);
      DataSms = "GPS Invalid, Lokasi tidak ditemukan";
      
      SendMessage();
      delay(1000*60*5);
    
  }

}
Last edited by dinihuygens on Fri Dec 18, 2020 6:58 am, edited 2 times in total.
User avatar
fpiSTM
Posts: 862
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 33
Location: Le Mans
Contact:

Re: Multiple serial port at the same time doesn't work

Post by fpiSTM »

Serial2 seems not used?

Note that HardwareSerial use IT so if several HS are required ensure to not block them.
dinihuygens
Posts: 13
Joined: Thu Dec 17, 2020 9:20 am
Answers: 1

Re: Multiple serial port at the same time doesn't work

Post by dinihuygens »

I use it for my GPS, and I have called it in void setup. What I'm supposed to do to make the HW serial not blocking each other?
ozcar
Posts: 41
Joined: Wed Apr 29, 2020 9:07 pm
Answers: 1

Re: Multiple serial port at the same time doesn't work

Post by ozcar »

dinihuygens wrote:
Thu Dec 17, 2020 5:49 pm
I use it (Serial2) for my GPS, and I have called it in void setup.
For this to work, surely you have to do more than just the Serial2.begin(9600) in setup()?

From the TinyGPS++ examples I can find, you would have to execute gps.encode(Serial2.read()) whenever there is Serial2 data available, but this is nowhere to be seen in your code. Maybe it is in ReceiveMode(), but you don't show that.
User avatar
fpiSTM
Posts: 862
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 33
Location: Le Mans
Contact:

Re: Multiple serial port at the same time doesn't work

Post by fpiSTM »

I'm agreed with [mention]ozcar[/mention]
Your code is not complete. I already used several serial without any issue even with huge load of data or by doing some customization rx or tx buffer increase.
dinihuygens
Posts: 13
Joined: Thu Dec 17, 2020 9:20 am
Answers: 1

Re: Multiple serial port at the same time doesn't work

Post by dinihuygens »

so nice of you guys, thank you it's solved. I was wrong choosing my board part number :|
I have made a little change to my code above in case someone needs it ;)
Post Reply

Return to “General discussion”