[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!
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: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
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: 143
Joined: Wed Apr 29, 2020 9:07 pm
Answers: 5

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: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

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

Post by fpiSTM »

I'm agreed with @ozcar
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 ;)
Hamza ASSA
Posts: 4
Joined: Tue Jun 01, 2021 12:15 pm

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

Post by Hamza ASSA »

dinihuygens
Hi friend,
actually, i am working on the same project.
I would interface the gps neo 6m with stm32 bluepill.
I programme with Arduino ide.
my one code doesn't work . Can you share yours. I hope that it will work.
Thank you.
I really need it because i ma blocked !!!
AndrewBCN
Posts: 105
Joined: Sun Apr 25, 2021 3:50 pm
Answers: 1
Location: Strasbourg, France

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

Post by AndrewBCN »

Hamza ASSA wrote: Thu Jun 03, 2021 7:25 pm dinihuygens
Hi friend,
actually, i am working on the same project.
I would interface the gps neo 6m with stm32 bluepill.
I programme with Arduino ide.
my one code doesn't work . Can you share yours. I hope that it will work.
Thank you.
I really need it because i ma blocked !!!
Please read this: https://github.com/stm32duino/wiki/wiki ... wareserial

Most examples included with the TinyGPS++ library work with simple mods.
mwon
Posts: 6
Joined: Fri May 21, 2021 12:25 pm

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

Post by mwon »

I'm having a similar problem and a strange behavior when using a BlackPill with a STM32F4C11CE. The code I show below compiles an run but for some reason the RPI serial ports are printing the data that was supposed to got to the DEBUG ports. I'm listening to the RPI pins (PB7 and PB6) and I'm reading "debug" at startup.

Code: Select all

HardwareSerial RPI(PB7,PB6);
HardwareSerial DEBUG(PA10,PA9);

void setup() {

  RPI.begin(115200);
  DEBUG.begin(115200); // begin Serial
  delay(1000);
  DEBUG.println("debug");
  RPI.println("RPI");

}

void loop() {


}
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

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

Post by ag123 »

@mwon

both PA9, PA10 and PB6, PB7 are going to USART1
if you want them to be different you should use a different serial port e.g. USART2
Post Reply

Return to “General discussion”