Hardware Serial returning gibberish.

Post here first, or if you can't find a relevant section!
Post Reply
smudge_smiff
Posts: 3
Joined: Sun Jul 16, 2023 1:52 pm

Hardware Serial returning gibberish.

Post 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!
ag123
Posts: 1732
Joined: Thu Dec 19, 2019 5:30 am
Answers: 27

Re: Hardware Serial returning gibberish.

Post 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
smudge_smiff
Posts: 3
Joined: Sun Jul 16, 2023 1:52 pm

Re: Hardware Serial returning gibberish.

Post 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.
ozcar
Posts: 146
Joined: Wed Apr 29, 2020 9:07 pm
Answers: 5

Re: Hardware Serial returning gibberish.

Post by ozcar »

Try

Code: Select all

Serial.write(gpsSerial.read());
Post Reply

Return to “General discussion”