cancel
Showing results for 
Search instead for 
Did you mean: 

Some chars trasmitted by USART (using HAL) are received wrong by the Serial Monitor on my PC

Daniele Paolini
Associate
Posted on May 24, 2018 at 12:14

Hello Community,

I am using the function HAL_UART_Transmit to send a string of 4 character in output to a display. I order to test the function first I am using a serial monitor (TERMITE) on my PC but i got this problem in the title.

I am using NUCLEO-H743ZI with HAL libraries generated with CubeMX and this is my code in the main file:

uint8_t mbuff[1];

uint8_t transBuff[4];

mbuff[0]='d';

transBuff[0]='c';

transBuff[1]='o';

transBuff[2]='s';

transBuff[3]='a';

HAL_UART_Transmit(&huart3, transBuff, 1, 200);

HAL_Delay(1000);

printf('\n....');

HAL_UART_Transmit(&huart3, (uint8_t *)mbuff, sizeof(mbuff), 200);

 HAL_Delay(1000);

  printf('\n');

in the first case when i send mbuff i receive 'd' and  that is correct, but when I send a string with more than one character (transBuff) instead of receiving 'cosa' i receive 'c7a'.

Has anyone got the same problem?

the configuration of USART is the following:

void MX_USART3_UART_Init(void)

{

  huart3.Instance = USART3;

  huart3.Init.BaudRate = 115200;

  huart3.Init.WordLength = UART_WORDLENGTH_7B;

  huart3.Init.StopBits = UART_STOPBITS_1;

  huart3.Init.Parity = UART_PARITY_NONE;

  huart3.Init.Mode = UART_MODE_TX_RX;

  huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE;

  huart3.Init.OverSampling = UART_OVERSAMPLING_16;

  huart3.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;

  huart3.Init.Prescaler = UART_PRESCALER_DIV2;

  huart3.Init.FIFOMode = UART_FIFOMODE_DISABLE;

  huart3.Init.TXFIFOThreshold = UART_TXFIFO_THRESHOLD_1_8;

  huart3.Init.RXFIFOThreshold = UART_RXFIFO_THRESHOLD_1_8;

  huart3.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;

  if (HAL_UART_Init(&huart3) != HAL_OK)

  {

    _Error_Handler(__FILE__, __LINE__);

  }

}

All the setting in the serial monitor are correct. Using Printf function the reception is always good but using the HAL_UART_Transmit function with more than one character there are some problems. Could be a problem with the clock syncronization? Should be better to decreas the BAUD rate in this case?

Thank you

#hal_uart_transmit #stm32cube_fw_h7_v1.0.0 #usart #nucleo-h743zi
1 REPLY 1
Tilen MAJERLE
ST Employee
Posted on May 24, 2018 at 14:41

Hello,

your UART is configured in 7-bits word length and it is causing wrong configuration in your terminal (most probably).

huart3.Init.WordLength = UART_WORDLENGTH_7B; //Your configuration
huart3.Init.WordLength = UART_WORDLENGTH_8B; //Most probably expected on terminal side�?�?

Best regards,

Tilen