Page 1 of 2

STM32DUİNO WİTH GPS

Posted: Fri Sep 10, 2021 4:31 pm
by engineer
hi, i am trying to get data from neo gps using stm but it is not working. It connects a usb ttl to pa9 and ps10 pins. Is there a code to get data from gps with stm?

I GET THIS ERROR
C:\Program Files (x86)\Arduino\libraries\SoftwareSerial\SoftwareSerial.cpp:501:21: error: 'SREG' was not declared in this scope
uint8_t oldSREG = SREG;
^
C:\Program Files (x86)\Arduino\libraries\SoftwareSerial\SoftwareSerial.cpp:502:7: error: 'cli' was not declared in this scope
cli();
^
exit status 1
Generic STM32F103C series kartı için derleme hatası.


this is the code i use

#include <TinyGPS.h>
TinyGPS gps;
#include <SoftwareSerial.h>
SoftwareSerial ss(PA10, PA9); //rx tx


void setup() {
Serial.begin(9600);
ss.begin(9600);
}

void loop() {
smartdelay(1000);
Serial.println();

uint8_t sat = gps.satellites();
Serial.print("Bağlanılan Uydu Sayısı: "); Serial.println(sat);

float flat, flon;
unsigned long age;
gps.f_get_position(&flat, &flon, &age);
Serial.print("Enlem: "); Serial.println(flat, 8);
Serial.print("Boylam: "); Serial.println(flon, 8);

int alt = gps.f_altitude();
Serial.print("Rakım: "); Serial.println(alt);

int spd = gps.f_speed_kmph();
Serial.print("Hız: "); Serial.println(spd);

int crs = gps.f_course();
Serial.print("Rota: "); Serial.println(crs);

int year;
byte month, day, hour, minute, second, hundredths;
unsigned long age2;
gps.crack_datetime(&year, &month, &day, &hour, &minute, &second, &hundredths, &age2);

Serial.print("Yıl: "); Serial.println(year);
Serial.print("Ay: "); Serial.println(month);
Serial.print("Gün: "); Serial.println(day);

Serial.print("Saat: "); Serial.println(hour + 3);//Utc cinsinden olan saati yerel saate çevirmek için (+3)yaptık
Serial.print("Dakika: "); Serial.println(minute);
Serial.print("Saniye: "); Serial.println(second);
}

static void smartdelay(unsigned long ms) {
unsigned long start = millis();
do {
while (ss.available())
gps.encode(ss.read());
} while (millis() - start < ms);
}

Re: STM32DUİNO WİTH GPS

Posted: Fri Sep 10, 2021 5:19 pm
by fpiSTM
Hi @engineer
Which core you used ? I guess you used Maple core (from Roger) as it has no SoftwareSerial library ported to STM32.
In that case you should update your code to use an hardware Serial instance instead.

Or try to use the STM32 core which have this library ported to STM32.

Re: STM32DUİNO WİTH GPS

Posted: Fri Sep 10, 2021 7:42 pm
by mrburnette
Long, long time ago on a BluePill board...
For Libmaple (Roger's stuff...)
From around 2016 so no guarantees!

Code: Select all

/*
   bluepill specific version that works
    http://stm32duino.com/viewtopic.php?f=13&t=6&start=40
    Sketch uses 16,804 bytes (13%) of program storage space. Maximum is 122,880 bytes.
    Global variables use 3,024 bytes of dynamic memory.
*/

#include <SoftSerialIntCC.h>
#define LED_BUILTIN 13

SoftSerialInt softserial1(PB7, PB6, 4);
SoftSerialInt softserial2(PA1, PA0, 2);

void setup()
{
  // set the data rate for the SoftwareSerial port
  softserial1.begin(115200);
  softserial2.begin(9600);
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, HIGH);
}

void loop() // run over and over
{
  softserial1.println("Type away");
  while (1) {
    if ( softserial1.available() ) {
      digitalWrite(LED_BUILTIN, LOW);
      int c = softserial1.read();
      softserial2.write((uint8_t)c);
      softserial1.write((uint8_t)c);
      digitalWrite(LED_BUILTIN, HIGH);
    }
  }
}

Re: STM32DUİNO WİTH GPS

Posted: Fri Sep 10, 2021 7:52 pm
by mrburnette
At one time, Jan 2018, this worked for TinyGPS...

Code: Select all

// see: http://stm32duino.com/viewtopic.php?f=3&t=3087&start=10#p39770
/*  IDE 1.8.5
Sketch uses 20136 bytes (16%) of program storage space. Maximum is 122880 bytes.
Global variables use 2952 bytes (14%) of dynamic memory, leaving 17528 bytes for local variables. Maximum is 20480 bytes.
 */
#include <TinyGPS.h>
#include <Arduino.h>
// -----------------gps
TinyGPS gps;
#define ss3 Serial2
static const uint32_t GPSBaud = 9600;
// -----------------gps

void setup()
{
  Serial.begin(9600);
  ss3.begin(GPSBaud);
}
uint32_t time;
void loop()
{
  if ( (millis() - time) < 1000 )
  {
    if (ss3.available())
    {
      char c = ss3.read();
      Serial.write(c); // monitor the data from GPS on PC
      gps.encode(c);
    }
    float flat, flon;
    unsigned long age;
    gps.f_get_position(&flat, &flon, &age);
    Serial.print("LAT=");
    Serial.print(flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flat, 6);
    Serial.print(" LON=");
    Serial.print(flon == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flon, 6);
    Serial.print(" SAT=");
    Serial.print(gps.satellites() == TinyGPS::GPS_INVALID_SATELLITES ? 0 : gps.satellites());
    Serial.print(" PREC=");
    Serial.print(gps.hdop() == TinyGPS::GPS_INVALID_HDOP ? 0 : gps.hdop());
  }
}

Re: STM32DUİNO WİTH GPS

Posted: Sat Sep 11, 2021 10:33 am
by engineer
i still get this error
C:\Program Files (x86)\Arduino\libraries\SoftwareSerial\SoftwareSerial.cpp:502:7: error: 'cli' was not declared in this scope
cli();
^
exit status 1
Generic STM32F103C series kartı için derleme hatası.

what do you think is the problem?

Re: STM32DUİNO WİTH GPS

Posted: Sat Sep 11, 2021 10:49 am
by engineer
I tried this code, I didn't get any error, but no text appeared on the serial port. This time I connected the tx pin of the gps to A4 of the A3 rx pin.

Re: STM32DUİNO WİTH GPS

Posted: Sat Sep 11, 2021 11:12 am
by ag123
Comment SoftwareSerial and use Serial1 in place of all the Serial references.
Add

Code: Select all

void Setup() {
	Serial1.begin(115200);
}
The baud rate needs to match what is there on your GPS. Line discipline is normally 8N1 default.
Serial1 use PA9, PA10 (uart1) default. Hardware serial is just there and just works.
It is quite similar for official core
https://github.com/stm32duino/wiki/wiki ... wareserial

Re: STM32DUİNO WİTH GPS

Posted: Sat Sep 11, 2021 1:14 pm
by engineer
YOU'RE SAYING YES IS VERY CORRECT BUT I ATTACHED USB TTL TO THESE PINS(a9 a10). Doesn't serial2 here show pins a3 and a2 of stm? Now I think the problem is entirely related to the pins. so when I connect both usb ttl and gps to a9 and a10, the code gives an error.

I made the code like this neo7m gps green light is blinking but still nothing is written on serial port

#include <TinyGPS.h>
#include <Arduino.h>
// -----------------gps
TinyGPS gps;

#define PIN_SERIAL3_RX PB11
#define PIN_SERIAL3_TX PB10
#define ss3 Serial3 //rx tx
static const uint32_t GPSBaud = 9600;
// -----------------gps

void setup()
{
Serial.begin(9600);
ss3.begin(GPSBaud);
}
uint32_t time;
void loop()
{
if ( (millis() - time) < 1000 )
{
if (ss3.available())
{
char c = ss3.read();
Serial.write(c); // monitor the data from GPS on PC
gps.encode(c);
}
float flat, flon;
unsigned long age;
gps.f_get_position(&flat, &flon, &age);
Serial.print("LAT=");
Serial.print(flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flat, 6);
Serial.print(" LON=");
Serial.print(flon == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flon, 6);
Serial.print(" SAT=");
Serial.print(gps.satellites() == TinyGPS::GPS_INVALID_SATELLITES ? 0 : gps.satellites());
Serial.print(" PREC=");
Serial.print(gps.hdop() == TinyGPS::GPS_INVALID_HDOP ? 0 : gps.hdop());
}
}

Re: STM32DUİNO WİTH GPS

Posted: Sat Sep 11, 2021 7:14 pm
by mrburnette
engineer wrote: Sat Sep 11, 2021 10:49 am I tried this code, I didn't get any error, but no text appeared on the serial port. This time I connected the tx pin of the gps to A4 of the A3 rx pin.
I used my QBF back in the old days to test serial in/out
https://forum.arduino.cc/t/the-qbf-the- ... ags/229468

Re: STM32DUİNO WİTH GPS

Posted: Sat Sep 11, 2021 9:45 pm
by ag123
The thing about baud rates is if the baud rates is wrong u'd get completely scrambled data or nothing !
The usual trick for this is to send a command in which you expect a response you know.
The easy way is to look up the manual and get the correct baud rates to talk to the GPS, it may not be 9600. You would need to check it.
The hard way is to write a little program (sketch) that does serial.begin(baud) for different baud rates and try 'talking' or 'listening to the GPS.
e.g.

Code: Select all

void setup() {
	Serial.begin(); // This one is usb - serial
	Serial1.begin(9600); //this goes to the gps
}

uint32_t gpsbaud = 9600;

void loop() {
	Serial.print("gpsbaud:");
	Serial.println(gpsbaud);
	Serial1.begin(gpsbaud);
	uint32_t start = millis();
	while(millis() - start < 10000) { //probe for 10 secs
		if (Serial1.available()) 
			while(Serial1.available()) { //print out whatever is received from gps to usb
				int8_t c = Serial1.read();
				Serial.print(c);
			}
		delay(1);
	}
	Serial.println();
	gpsbaud += 1200;
	if(gpsbaud > 1000000) while(1); //loop forever	
}
You can make the codes more 'intelligent' by printing messages that contain only readable characters
http://facweb.cs.depaul.edu/sjost/it212 ... cii-pr.htm
this is the most crude form of 'auto bauding', i.e. keep printing the received data at different baud rates till you see something sane.

In addition, GPS is normally 'quiet' unless it 'sees' satellites in the open sky. If they aren't there, maybe it'd just remain silent.