I'm trying to read my GNSS module using STM32 Nucleo-WL55JC1. Here's my main loop code first
while (1)
{
uint8_t buff[500];
HAL_UART_Receive(&huart1, buff, strlen((char*)buff), HAL_MAX_DELAY);
HAL_UART_Transmit(&huart2, buff, strlen((char*)buff), HAL_MAX_DELAY);
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
When I run the code my serial monitor only print few messages and then it freezes
$PSTMVER,GNSSLIB_8.4.18.25_CP_ARM*07
$GPTXT,DEFAULT LIV3FL CONFIGURATION*12
$PSTMVER,OS20LIB_4.4.0_ARM*40
$PSTMVER,GPSAPP_2.11.0_CP_LIV3FL_RC9_ARM*20
$PSTMVER,BINIMG_4.6.15_CP_LIV3FL_RC9_ARM*27
Then I changed the receive timeout to 1000
it started outputing some NMEA data, but as you can see it mixed up with other messages
$PSTMCPU,20.86,-1,98*4F
$GPRMC,060732.000,V,0745.75046,S,11023.31916,E,,,071222,,,N*64 $GPGGA,060732.000,0745.75046,S,11023.31916,E,0,00,99.0,172.57,M,0.0,M11023.31916,E,060731.000,V,N*54
Then I unplugged and try to plug the MCU and now it only looping on this message
$PSTMVER,GPSAPP_2.11.0_CP_LIV3FL_RC9_ARM*20
$PSTMVPSTMVER,OS20LIB_4.4.0_ARM*40
$PSTMVER,GPSAPP_2.11.0_CP_LIV3FL_RC9_ARM*20
$PSTMVPSTMVER,OS20LIB_4.4.0_ARM*40
$PSTMVER,GPSAPP_2.11.0_CP_LIV3FL_RC9_ARM*20
$PSTMVPSTMVER,OS20LIB_4.4.0_ARM*40
I've tried using the same module on ESP it prints the message correctly
$PSTMCPU,21.69,-1,98*4F
$GPRMC,062153.000,V,0745.76371,S,11023.30606,E,,,071222,,,N*6C
$GPGGA,062153.000,0745.76371,S,11023.30606,E,0,02,99.0,189.71,M,0.0,M,,*77
$GPVTG,,T,,M,,N,,K,N*2C
$GNGSA,A,1,26,27,,,,,,,,,,,99.0,99.0,99.0*1F
$GNGSA,A,1,,,,,,,,,,,,,99.0,99.0,99.0*1E
$GPGSV,2,1,05,26,53,342,32,27,39,189,27,22,35,019,,23,14,149,*75
$GPGSV,2,2,05,21,07,251,,,,,,,,,,,,,*4E
$GLGSV,2,1,06,70,70,053,,74,33,309,,71,29,352,,69,26,142,27*6F
$GLGSV,2,2,06,80,15,158,,85,11,205,,,,,,,,,*69
$GPGLL,0745.76371,S,11023.30606,E,062153.000,V,N*5F
This is my first time using STM32 IDE and its HAL (I only use Arduino IDE before) so I kinda lost why my output is really different compared with the ESP.
Edit 1
As chux - Reinstate Monica's suggests I've modified the code to the following
uint8_t buff[500];
ret = HAL_UART_Receive(&huart1, buff, sizeof buff , HAL_MAX_DELAY);
while(ret != HAL_OK); // Continue when Receive returns HAL_OK
HAL_UART_Transmit(&huart2, buff, sizeof buff, HAL_MAX_DELAY);
The stuck problem is still there, but the output now changes to
$PSTMVER,GNSSLIB_8.4.18.25_CP_ARM*07
$GPTXT,DEFAULT LIV3FL CONFIGURATION*12
$PSTMVER,OS20LIB_4.4.0_ARM*40
$PSTMVER,GPSAPP_2.11.0_CP_LIV3FL_RC9_ARM*20
$PSTMVER,BINIMG_4.6.15_CP_LIV3FL_RC9_ARM*27
$PSTMVER,SWCFG_8306532d*33
$PSTMVER,STAGPSLIB_6.0.0_ARM*5A
$PSTMVER,STA8090_822bc043*61
$GPTXT,(C)2000-2018 ST Microelectronics*29
$GPTXT,DEFAULT LIV3FL CONFIGURATION*12
$PSTMSWCONFIG,1,0,12,000205f105070a0a0e0d0c0b0a090608070203630e110c04180c0155030110500f00000f071402050a40fffffffffffffffffffff (stuck here)
Reflashing without unplug and plugging the MCU
$GNGSA,A,3,03,16,32,27,26,22,,,,,,,1.9,1.0,1.6*26
$GNGSA,A,3,,,,,,,,,,,,,1.9,1.0,1.6*22
$GPGSV,3,1,10,16,58,305,23,27,53,179,23,32,47,086,23,22,46,034,22*72
$GPGSV,3,2,10,26,39,354,20,10,30,157,14,08,25,206,13,03,14,310,27*7B
$GPGSV,3,3,10,31,12,021,,21,10,237,,,,,,,,,*7E
$GLGSV,2,1,08,70,72,122,,71,48,350,,84,23,127,,74,22,326,*6C
$GLGSV,2,2,08,75,19,269,19,85,17,189,,6开发者_运维百科9,11,151,18,80,11,144,19*6B
$GPGLL,0745.76098,S,11023.30836,E,065605.000,A,A*4D
$PSTMCPU,36.35,-1,98*40
$G (stuck here)
strlen((char*)buff)
is invalid as the contents of buff
are indeterminate.
Consider HAL_UART_Receive(&huart1, buff, sizeof buff, HAL_MAX_DELAY);
.. and use the return value of HAL_UART_Receive()
to determine success level.
HAL_UART_Transmit()
should only attempt to transmit the number of characters received, not strlen((char*)buff)
.
精彩评论