cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_UART_Transmit doesn't work

andreaspiezia9
Associate III

Hi,

I'm simply want transmit on UART using code generated by CUBEMX 5.1.0 for NUCLEO F401RE in System Workbench (Version: Neon.3 Release (4.6.3)).

I've only added the following code in the main:

UartStatus is ALWAY HAL_OK after every transmission. I'm using Tera Term to see the serial data on COM5.

Thanks for help!

0690X000008BH2TQAW.png

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    /* USER CODE END WHILE */
  uint8_t buffer [] = {0,1,2,3};
  UartStatus = HAL_UART_Transmit(&huart2, buffer, 4, 1000);
  if (UartStatus != HAL_OK)
  {
	  HAL_Delay(1000);
  }
 
  HAL_Delay(1000);
    /* USER CODE BEGIN 3 */
 }
  /* USER CODE END 3 */
 
static void MX_USART2_UART_Init(void)
{
 
  /* USER CODE BEGIN USART2_Init 0 */
 
  /* USER CODE END USART2_Init 0 */
 
  /* USER CODE BEGIN USART2_Init 1 */
 
  /* USER CODE END USART2_Init 1 */
  huart2.Instance = USART2;
  huart2.Init.BaudRate = 115200;
  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();
  }
  /* USER CODE BEGIN USART2_Init 2 */
 
  /* USER CODE END USART2_Init 2 */
 
}
 

1 ACCEPTED SOLUTION

Accepted Solutions
Pavel A.
Evangelist III

For testing, better use some printable characters rather than codes in control range.

Fore example

char buffer[] = "test";

HAL_UART_Transmit(&huart2, (void*)buffer, strlen(buffer), 1000);

-- pa

View solution in original post

2 REPLIES 2
Pavel A.
Evangelist III

For testing, better use some printable characters rather than codes in control range.

Fore example

char buffer[] = "test";

HAL_UART_Transmit(&huart2, (void*)buffer, strlen(buffer), 1000);

-- pa

Thanks a lot Pavel! Now works good.