cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F411 HAL USART Polling receiving garbled characters

vrouesnel
Associate II
Posted on March 02, 2015 at 02:47

I have a project configured the same as the `UART_Hyperterminal_DMA` example from the `STM32Cube_FW_F4_V1.4.0`.

I am reading NMEA strings from a GPS device. When I print byte-by-byte over virtual com (which I have confirmed works) I receive something that looks like this:

$GMCV,,,,,,*D
$GVT,,,,,,N*E
$NGA,,,,000999,,,*5
GNSA,1,,,,999,.999
$GSA,,,,,,9,999E
$PGV,,10079
$LV,10*
NG,,,,NA
$RM,V,,,,ND
VT,,,,N*
GNA,,,,0999,,6
GNA,1,,,,,9.9,9.9,9.9*E
$GGS,A1,,,,,,,9999999999992
GPSV,10*
L,1,5
GNL,,V,7AAAAAAAA$G,,,,,,,4D$G,,,,,N2
GNGA,,,,,0,9.,,,*6
$GGS,A1,,,,,,,9999999999*2
GNSAA,,,,,,,,9.,99*
PG,10*

I am using FreeRTOS. I have checked:
  • clock settings for USART1 bus are correct.
  • signals from gps with a logic analyzer are correct.
Here is a bit of my code:

void
USART::task(
void
const
*nothing) {
HAL_StatusTypeDef status;
status = HAL_UART_Receive(&huart1, (uint8_t *) aRxBuffer, RXBUFFERSIZE, 100);
osMessagePut(usartQueue, aRxBuffer[0], 0);
printf
(
''%c''
, aRxBuffer[0]);
while
((status != HAL_OK) || (status != HAL_TIMEOUT)) {
status = HAL_UART_Receive(&huart1, (uint8_t *) aRxBuffer, RXBUFFERSIZE, 100);
printf
(
''%c''
, aRxBuffer[0]);
osMessagePut(usartQueue, aRxBuffer[0], 0);
}
}
extern
''C''
{
void
HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) {
}
}

Would really appreciate any help. Thanks! #hal-usart-stm32f4xx-polling
5 REPLIES 5
Posted on March 02, 2015 at 03:45

Is the receiver buffer actually a single byte, or multiple. Not a HAL user, but looks to be specifying 100 characters (or some other unspecified size) but only ever printing/forwarding one.

Be careful to understand the number of characters, and that strings probably won't be NUL terminated.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
vrouesnel
Associate II
Posted on March 02, 2015 at 11:37

Hey Clive,

`RXBUFFERSIZE` is 1 so I don't think thats the problem.

Here is what the data from the logic analyzer looks like:

```

$GNGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*2E

$GNGSA,A,1,,,,,,,,,,,,,9999,99.99,99.99*2E

$GPGSV,1,1,00*79

$GLGSV,1,1,00*65

$GNGLL,,,,,,V,N*7A

$GNRMC,,V,,,,,,,,,,N*4D

$GNVTG,,,,,,,,,N*2E

$GNGGA,,,,,,0,00,99.99,,,,,,*56

$GNGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*2E

$GNGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*2E

$GPGSV,1,1,00*79

$GLGSV,1,1,00*65

$GNGLL,,,,,,V,N*7A

$GNRMC,,V,,,,,,,,,,N*4D

$GNVTG,,,,,,,,,N*2E

$GNGGA,,,,,,0,00,99.99,,,,,,*56

$GNGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*2E

$GNGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*2E

$GPGSV,1,1,00*79

$GLGSV,1,1,00*65

$GNGLL,,,,,,V,N*7A

$GNRMC,,V,,,,,,,,,,N*4D

$GNVTG,,,,,,,,,N*2E

$GNGGA,,,,,,0,00,99.99,,,,,,*56

$GNGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*2E

$GNGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*2E

$GPGSV,1,1,00*79

$GLGSV,1,1,00*65

$GNGLL,,,,,,V,N*7A

$GNRMC,,V,,,,,,,,,,N*4D

$GNVTG,,,,,,,,,N*2E

$GNGGA,,,,,,0,00,99.99,,,,,,*56

$GNGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*2E

$GNGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*2E

$GPGSV,1,1,00*79

$GLGSV,1,1,00*65

$GNGLL,,,,,,V,N*7A

$GNRMC,,V,,,,,,,,,,N*4D

$GNVTG,,,,,,,,,N*2E

$GNGGA,,,,,,0,00,99.99,,,,,,*56

$GNGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*2E

$GNGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*2E

$GPGSV,1,1,00*79

$GLGSV,1,1,00*65

$GNGLL,,,,,,V,N*7A

$GNRMC,,V,,,,,,,,,,N*4D

$GNVTG,,,,,,,,,N*2E

$GNGGA,,,,,,0,00,99.99,,,,,,*56

$GNGSA,A,1,,,,,,,,,,,

```

It seems to be randomly dropping bytes.
vrouesnel
Associate II
Posted on March 02, 2015 at 11:45

Increasing the buffer size to 100 then printing it produces a similar result:

```

$PGV,,1010,157A\n

$LGV,,101,,2*6\r\n

GNLL,,,14800V,5E$GNC,500,,,,205,6\n

$VT,,,,,,N*E$NGA,04590''

```
vrouesnel
Associate II
Posted on March 02, 2015 at 14:03

Have double checked baud rate to be correct:

`USART1_BRR = 0x222E = 8750 = 84000000/9600 = System Clock / Baud Rate`

AvaTar
Lead
Posted on March 02, 2015 at 15:12

Sorry for seemingly stupid questions, but I never used the Cube/HAL stuff.

What does your

HAL_UART_Receive

() looks like ? Do you get an interrupt on a DMA complete event ? That wouldn't make too much sense, you could pick up the uart interrupts directly instead. In case of multibyte DMA events or polling, how you avoid overflow ? Your GPS transceiver might push new characters in and overwrite the buffer you are about to read. Any chance to check the OV flag of the UART ? I never experienced such problems with interrupt-driven StdLib code, up to 115200 baud.