cancel
Showing results for 
Search instead for 
Did you mean: 

How do I maximize baudrate via USART with STM32L4P?

crackl1ng
Associate III

Hi STM32-Community,

I'm currently trying to maximize my dataouput. I've about 150 KB/s data, which are sent out via RS485 and connected with a RS485 to USB to my PC. The USART Clock is at 64 MHz, though 80 MHz viable aswell, which means I should be able to send data with 4 to 5 MBaud. However, the data is corrupted beyond a baudrate 256000 and I do not understand why. I also have oversampling at 16. Here is my USART init:

void MX_UART4_Init(void)
{
 
  /* USER CODE BEGIN UART4_Init 0 */
 
  /* USER CODE END UART4_Init 0 */
 
  /* USER CODE BEGIN UART4_Init 1 */
 
  /* USER CODE END UART4_Init 1 */
  huart4.Instance = UART4;
  huart4.Init.BaudRate = 256000;
  huart4.Init.WordLength = UART_WORDLENGTH_8B;
  huart4.Init.StopBits = UART_STOPBITS_1;
  huart4.Init.Parity = UART_PARITY_NONE;
  huart4.Init.Mode = UART_MODE_TX_RX;
  huart4.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  huart4.Init.OverSampling = UART_OVERSAMPLING_16;
  huart4.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
  huart4.Init.ClockPrescaler = UART_PRESCALER_DIV1;
  huart4.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
  if (HAL_UART_Init(&huart4) != HAL_OK)
  {
    Error_Handler();
  }
  if (HAL_UARTEx_SetTxFifoThreshold(&huart4, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK)
  {
    Error_Handler();
  }
  if (HAL_UARTEx_SetRxFifoThreshold(&huart4, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK)
  {
    Error_Handler();
  }
  if (HAL_UARTEx_DisableFifoMode(&huart4) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN UART4_Init 2 */
 
  /* USER CODE END UART4_Init 2 */
 
}

I'm trying to read the data with Matlab/Terminal, but the data keeps being received wrong.

I'm thankful for every advice.

Kind regargds

13 REPLIES 13
Andrew Neil
Evangelist III

Have you looked at the signals on an oscilloscope?

@TDK​ "The start bit is much too short on most or all of the bytes."

That could be the result of too-slow edges - so the LA's 0/1 threshold doesn't happen where it should ...

Use a scope to look at the signals at the receiver inputs.

@crackl1ng​ ,

to cover any reasonable distance with RS-485 you need to use a transceiver:

RS-422 RS-423 RS-485 - STMicroelectronics

With that IC added, you can achieve 5MBaud on distance of maybe 20 meters, depending on circumstances.

If you are connecting the STM32 directly with the USB converter, I'm quite impressed even 1.5m is possible. BTW you can use 1.5M USB cable and put the converter like 5cm from the STM32, which should also help.

BR,

J

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Other edges are fine, so I don't see how that could be the case. They would all be delayed the same amount. It is consistently the start bit that is off.

If you feel a post has answered your question, please click "Accept as Solution".

would still be worth looking on a scope - to see what's actually happening in the analogue domain ...