cancel
Showing results for 
Search instead for 
Did you mean: 

Using 2 UART on STM32?

antonius
Senior

Dear Members,

I want to read a result from my GPS,

it's Neo 6M

I initialized 2 UARTs UART 1 for PC and UART 2 for GPS,

I got this result :

INIT CODE GPS NEO - 6M....

                           

From GPS : 0690X0000087jMhQAI.png

Is it receiving properly ?

The code :

 char in[8];

printf("From GPS : ");

  HAL_UART_Receive(&huart2, (uint8_t *)in, 8, 1000);

HAL_UART_Transmit(&huart1, (uint8_t *)in, 8, 1);

printf("\r\n");

Green LED on GPS module is blinking...

Thanks

35 REPLIES 35

I would expect NMEA sentences at 9600 8N1

Your HAL functions block, so no ideal for forwarding data.​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
AvaTar
Lead

> I would expect NMEA sentences at 9600 8N1

This are the default setting of the module.

Do you have the baudrate of the STM32 MCU set properly ?

And not changed the module's setting to binary UBX messages ?

In addition to the inappropriateness of said HAL functions.

Seems too consistent and wrong data to be UBX. Would need to know more about specific implementation. NAZA​ UAV modules for example output their own packet format.

One could observe data with a scope, or use USB to CMOS Serial directly from NEO-6M module.​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Does the receive call function or does it return an error? Try clearing the buffer and checking. Post lacks a lot of salient details which would help diagnose situation.

To answer the underlying question, No this doesn't look to be receiving properly/correctly. ​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
antonius
Senior
void MX_USART1_UART_Init(void)
{
 
  huart1.Instance = USART1;
  huart1.Init.BaudRate = 115200;
  huart1.Init.WordLength = UART_WORDLENGTH_8B;
  huart1.Init.StopBits = UART_STOPBITS_1;
  huart1.Init.Parity = UART_PARITY_NONE;
  huart1.Init.Mode = UART_MODE_TX_RX;
  huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  huart1.Init.OverSampling = UART_OVERSAMPLING_16;
  if (HAL_UART_Init(&huart1) != HAL_OK)
  {
    Error_Handler();
  }
 
}
/* USART2 init function */
 
void MX_USART2_UART_Init(void)
{
 
  huart2.Instance = USART2;
  //huart2.Init.BaudRate = 115200;
	huart2.Init.BaudRate = 9600;//NEO6M Baudrate
  huart2.Init.WordLength = UART_WORDLENGTH_8B;
  huart2.Init.StopBits = UART_STOPBITS_1;
  huart2.Init.Parity = UART_PARITY_NONE;
  huart2.Init.Mode = UART_MODE_TX_RX;
  huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  huart2.Init.OverSampling = UART_OVERSAMPLING_16;
  if (HAL_UART_Init(&huart2) != HAL_OK)
  {
    Error_Handler();
  }
 
}

UART Setting from STM32CubeMX

@Clive

Which UART buffer should I clear ?

antonius
Senior

I'm using the module indoor, does it receive signal ?

Or without a signal, at least I can read its ID with UART ?

Is this the right manual ?

https://www.terraelectronica.ru/pdf/show?pdf_file=%2Fz%2FDatasheet%2FU%2FUART+GPS+NEO-6M+User+Manual.pdf

or there's another more comprehensive one ?

Thanks

antonius
Senior
antonius
Senior
antonius
Senior

I got output from

serial to PC

0690X0000087xX0QAI.png

May be with interrupt is better ?

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)

{

display to pc here

}