[Solved] Multiple serial port at the same time doesn't work
Posted: Thu Dec 17, 2020 10:58 am
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:
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);
}
}