2021-01-29 09:36 PM
Hello Forum,
I am using stm32f030cct6 and Quectel L86 GPS module for my application.
I am doing coding on STMCubeIDE, using HAL libraries.
The GPS module is in continuously receiving data mode.
I am receiving that data on uart in a buffer.
Max size of buffer i kept is 1500, which is sufficient.
My main question is that while receiving the data i need to clear the previously stored data from buffer.
For a while it receives variation in data but after some time it keep same data till reset of MCU.
I want to clear the previous data as it receives fresh data each second.
Can anyone tell me how to do that?
This is the data that received on UART
$PMTK011,MTKGPS*08
$PMTK010,001*2E
$PMTK011,MTKGPS*08
$PMTK010,002*2D
$GPRMC,064512.498,V,,,,,0.00,0.00,270121,,,N*4B
$GPVTG,0.00,T,,M,0.00,N,0.00,K,N*32
$GPGGA,064512.498,,,,,0,0,,,M,,M,,*49
$GPGSA,A,1,,,,,,,,,,,,,,,*1E
$GPGSV,1,1,00*79
$GLGSV,1,1,00*65
$GPGLL,,,,,064512.498,V,N*7B
$GPTXT,01,01,02,ANTSTATUS=OPEN*2B
$GPRMC,064513.498,V,,,,,0.00,0.00,270121,,,N*4A
$GPVTG,0.00,T,,M,0.00,N,0.00,K,N*32
$GPGGA,064513.498,,,,,0,0,,,M,,M,,*48
$GPGSA,A,1,,,,,,,,,,,,,,,*1E
$GPGSV,1,1,00*79
$GLGSV,1,1,00*65
$GPGLL,,,,,064513.498,V,N*7A
$GPTXT,01,01,02,ANTSTATUS=OPEN*2B
2021-01-29 11:26 PM
Sounds like an issue with your code (not shown). Use memset to clear the buffer before the next message comes in?
Receive with HAL_UARTEx_ReceiveToIdle_IT(&huart2, &buffer, sizeof(buffer) ); and in the callback, you get the number of bytes read:
void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size)
{
// process message of size Size in buffer
HAL_UARTEx_ReceiveToIdle_IT(&huart2, &buffer, sizeof(buffer) );
}
2021-01-30 03:07 AM
Hello @KnarfB,
Thanks for the reply.
I am using
HAL_UART_Receive(&GPSUART,(uint8_t *)ch,MAX,500); /* Receiving data from GPS on UART_1*/
str_len = strlen(ch);
HAL_UART_Transmit(&TerminalUART,(uint8_t *)ch,str_len,500); /*Transmitting data to Terminal UART_2*/
this in while loop
when i use memset after transmit loop get stops
2021-01-30 03:23 AM
Put memset immediately before HAL_UART_Receive.
Note that HAL_UART_Receive returns after either MAX bytes were read or the timeout (500ms) elapsed.
2021-01-30 04:40 AM
An array of some data is not a zero terminated string. You cannot use strlen() or other string manipulation functions on it.
2021-02-04 12:25 AM
Hello @KnarfB , @Piranha
I use memset before receiving data
memset(ch,0,MAX);
HAL_UART_Receive(&GPSUART,(uint8_t *)ch,MAX,1000); /* Receiving data from GPS on UART_1*/
str_len = strlen(ch);
HAL_UART_Transmit(&TerminalUART,(uint8_t *)ch,str_len,1000);/*Transmitting data to Terminal UART_2*/
and i got this output
$PMTK011,MTKGPS*08
$PMTK010,001*2E
$PMTK011,MTKGPS*08
$PMTK010,002*2D
$GPRMC,063153.974,V,,,,,0.00,0.00,040221,,,N*40
$GPVTG,0.00,T,,M,0.00,N,0.00,K,N*32
$GPGGA,063153.974,,,,,0,0,,,M,,M,,*40
$GPGSA,A,1,,,,,,,,,,,,,,,*1E
$GPGSV,1,1,00*79
$GLGSV,1,1,00*65
$GPGLL,,,,,063153.974,V,N*72
$GPTXT,01,01,02,ANTSTATUS=OPEN*2B
330
$GPRMC,063154.974,V,,,,,0.00,0.00,040221,,,N*47
$GPVTG,0.00,T,,M,0.00,N,0.00,K,N*32
$GPGGA,063154.974,,,,,0,0,,,M,,M,,*47
$GPGSA,A,1,,,,,,,,,,,,,,,*1E
$GPGSV,1,1,00*79
$GLGSV,1,1,00*65
$GPGLL,,,,,063154.974,V,N*75
$GPTXT,01,01,02,ANTSTATUS=OPEN*2B
256
$
1
and HAL_UART_Receive returns after timeout
2021-02-04 12:34 AM
Hello @Piranha ,
I didn't understand your point regarding the manipulation.
2021-02-05 10:24 PM
Hello @KnarfB ,
I need some updates on this.
2021-10-28 12:02 PM
https://www.youtube.com/watch?v=EsZLgqhqfO0&t=455s - watch right after the 13-minute mark. Maybe this can give you an idea. There is a (Rx/Tx)HalfCpltCallback or something in the HAL_Drivers. And UART can also use DMA.