Page 1 of 1

Hardware Serial returning gibberish.

Posted: Tue Mar 26, 2024 10:02 pm
by smudge_smiff
I have a GPS connected to my STM32F401CC.

The hardware Serial is returning nonsense into the program.

I know the GPS is working at 57600 Baud as I have a USB-Serial adapter and it is producing the NEMA strings as expected. However, when I read the serial using the STM32, I get nothing but gibberish forwarded to the PC.

Code for Reference:

Code: Select all

void position_task(void* args)
{
    HardwareSerial gpsSerial(UART2_RX, UART2_TX);
    gpsSerial.begin(57600);
    for(;;)
	{
		while(gpsSerial.available() > 0){
            Serial.print(gpsSerial.read());
        }
	}
}

Any help is much appreciated!

Re: Hardware Serial returning gibberish.

Posted: Wed Mar 27, 2024 2:32 am
by ag123
many GPS device initialize at 9600 baud, not 57600 baud. and various of them offer commands to set the baud rates after initially connecting at 9600 bps

if you do not know the actual GPS bauds, to avoid getting gibberish, you would need to practically test every practical known baud, till one that doesn't return gibberish

Re: Hardware Serial returning gibberish.

Posted: Fri Mar 29, 2024 12:50 am
by smudge_smiff
57600 is the correct baud rate. I used a USB to Serial adapter to verify this and the correct functioning of the GPS. At 57600 the NEMA sentences are relieved as expected. The error is in the mcu.

Re: Hardware Serial returning gibberish.

Posted: Sun Mar 31, 2024 6:25 am
by ozcar
Try

Code: Select all

Serial.write(gpsSerial.read());