Having issues reading a UART string into a buffer, getting garbage data.
I am attempting to read a NEMA message from a GPS over UART.
Im expecting the message to be about 75 chars/bytes long.
Heres a sample of the data I'm seeing when using an ardunio for testing the GPS data out over UART.
$GNGGA,011112.00,3214.62073,N,05800.07397,W,2,12,1.14,22.0,M,-33.2,M,,0000*45
However when I use the code below I get a ton of junk data mixed in with good data.
HAL_UART_Receive_DMA(&huart1, &rxByte, 1);void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) {
if(rxByte == 0x6e && rx_buff[rxIdx--] == 0x5c || rxIdx >= 73) {
rx_buff[rxIdx] = rxByte;
sprintf(statusBuf, "%s", rx_buff);
CDC_Transmit_FS((uint8_t *) statusBuf, strlen(statusBuf));
memset(statusBuf, 0, 128);
rxFlag = 1;
rxIdx = 0;
}
else {
rx_buff[rxIdx] = rxByte;
rxIdx++;
}
HAL_UART_Receive_DMA(&huart1, &rxByte, 1);
}Example of the junk data being printed out
µb\ÿê®Õmˆ.òâÿÿ°dZ$GNGGA,023050.00,3214.87989,N,05800.08063,W,2,12,1.03,25.8,M,-3 0*49
µb\W,2,12,1.03,25.8,M,-33.2,M,,0000*4C
µb\œâÿÿ[d52.00,3214.87990,N,05800.08064,W,2,12,1.03,25.7,M,-33.2,M,,0000* ˜}ýå57%¦25.6,M,-33.2,M,,0000*47
µb\7993,N,05800.08056,W,2,12,0.98,25.4,M,-33.2,M,,0000*4F
µb\%,M,,0000*47
µb\.08061,W,2,12,0.98,25.3,M,-33.2,M,,0000*48
µb\®Õzˆ.“àÿÿQbGA,023057.00,3214.87996,N,05800.08062,W,2,12,0.98,25.2,M,-33.2,M
µb\2,1.38,25.1,M,-33.2,M,,0000*4A
µb\Âa,3214.87994,N,05800.08062,W,2,12,1.32,25.0,M,-33.2,M,,0000*47
µ M,-33.2,M,,0000*46Ideally I would like to read into the buffer until I see a \r\n and have a clean string I could split and parse.
I've tried using UART_IT, with a similar buffer method and ran into similar issues. Same with polling. However the data is clean and works great with other micros.
Im using an stm32f303c8t6.
