cancel
Showing results for 
Search instead for 
Did you mean: 

UART Transmission error (to computer using FTDI board )

JShim.1
Associate

I'm trying to UART Transmission to computer using FTDI board with below [Environmets.]

But it have a [problems] like below..

Please, let me know the reasons and solutions..:sad_but_relieved_face:

[Environments​]

  1. MCU : STM32L432 Nucleo-32 board
  2. FTDI Board : MIKROE USB UART Click Board
  3. Computer Interface : watching a data using PuTTY on Window 10
  4. IDE : STM32CubeIDE workspace 1.4.0
  5. MCU Pin/Clock Setting : Attached file(clock configuration), Attached file(pin setting)
  6. PuTTY Setting : Attached file(PuTTY Setting)

[Problem]

  1. Problem : As you can see in the Attached file(prob), My computer cannot recieve data from Nucleo board.
  2. Self diagnosis : (1) Using Osilloscope, I checked the UART TX Signals to FTDI(Click) Board. (2) Also, I set USART as Asynchronous Mode on the Cube MX.
  3. Code

int main(void)

{

 /* USER CODE BEGIN 1 */

 /* USER CODE END 1 */

 /* MCU Configuration--------------------------------------------------------*/

 /* Reset of all peripherals, Initializes the Flash interface and the Systick. */

 HAL_Init();

 /* USER CODE BEGIN Init */

 /* USER CODE END Init */

 /* Configure the system clock */

 SystemClock_Config();

 /* USER CODE BEGIN SysInit */

 /* USER CODE END SysInit */

 /* Initialize all configured peripherals */

 MX_GPIO_Init();

 MX_TIM16_Init();

 MX_USART2_UART_Init();

 /* USER CODE BEGIN 2 */

 /* USER CODE END 2 */

 while (1)

 {

 UART_TransmitHelloWorld();

 HAL_Delay(500);

  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */

 }

 /* USER CODE END 3 */

}

void SystemClock_Config(void)

{

 RCC_OscInitTypeDef RCC_OscInitStruct = {0};

 RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

 RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};

 /** Initializes the RCC Oscillators according to the specified parameters

 * in the RCC_OscInitTypeDef structure.

 */

 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;

 RCC_OscInitStruct.HSIState = RCC_HSI_ON;

 RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;

 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;

 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;

 RCC_OscInitStruct.PLL.PLLM = 1;

 RCC_OscInitStruct.PLL.PLLN = 10;

 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV7;

 RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2;

 RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2;

 if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)

 {

  Error_Handler();

 }

 /** Initializes the CPU, AHB and APB buses clocks

 */

 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK

               |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;

 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;

 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;

 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;

 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

 if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK)

 {

  Error_Handler();

 }

 PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART2;

 PeriphClkInit.Usart2ClockSelection = RCC_USART2CLKSOURCE_PCLK1;

 if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)

 {

  Error_Handler();

 }

 /** Configure the main internal regulator output voltage

 */

 if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK)

 {

  Error_Handler();

 }

}

/**

 * @brief TIM16 Initialization Function

 * @param None

 * @retval None

 */

static void MX_TIM16_Init(void)

{

 /* USER CODE BEGIN TIM16_Init 0 */

 /* USER CODE END TIM16_Init 0 */

 /* USER CODE BEGIN TIM16_Init 1 */

 /* USER CODE END TIM16_Init 1 */

 htim16.Instance = TIM16;

 htim16.Init.Prescaler = 80-1;

 htim16.Init.CounterMode = TIM_COUNTERMODE_UP;

 htim16.Init.Period = 65536-1;

 htim16.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;

 htim16.Init.RepetitionCounter = 0;

 htim16.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;

 if (HAL_TIM_Base_Init(&htim16) != HAL_OK)

 {

  Error_Handler();

 }

 /* USER CODE BEGIN TIM16_Init 2 */

 /* USER CODE END TIM16_Init 2 */

}

/**

 * @brief USART2 Initialization Function

 * @param None

 * @retval None

 */

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;

 huart2.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;

 huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;

 if (HAL_UART_Init(&huart2) != HAL_OK)

 {

  Error_Handler();

 }

 /* USER CODE BEGIN USART2_Init 2 */

 /* USER CODE END USART2_Init 2 */

}

/**

 * @brief GPIO Initialization Function

 * @param None

 * @retval None

 */

static void MX_GPIO_Init(void)

{

 GPIO_InitTypeDef GPIO_InitStruct = {0};

 /* GPIO Ports Clock Enable */

 __HAL_RCC_GPIOC_CLK_ENABLE();

 __HAL_RCC_GPIOA_CLK_ENABLE();

 __HAL_RCC_GPIOB_CLK_ENABLE();

 /*Configure GPIO pin Output Level */

 HAL_GPIO_WritePin(LD3_GPIO_Port, LD3_Pin, GPIO_PIN_RESET);

 /*Configure GPIO pin : LD3_Pin */

 GPIO_InitStruct.Pin = LD3_Pin;

 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;

 GPIO_InitStruct.Pull = GPIO_NOPULL;

 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;

 HAL_GPIO_Init(LD3_GPIO_Port, &GPIO_InitStruct);

}

/* USER CODE BEGIN 4 */

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)

{

 /* Prevent unused argument(s) compilation warning */

 UNUSED(huart);

 /* NOTE : This function should not be modified, when the callback is needed,

      the HAL_UART_RxCpltCallback can be implemented in the user file

  */

  HAL_UART_Transmit(&huart2, (uint8_t *)aRxBuffer, 10,0xFFFF);

}

void UART_TransmitHelloWorld()

{

  char *message = "Hello Nucleo Fun!\n\r";

  HAL_UART_Transmit(&huart2, (uint8_t *)message, strlen(message), 0xFFFF);

}

/* USER CODE END 4 */

/**

 * @brief This function is executed in case of error occurrence.

 * @retval None

 */

void Error_Handler(void)

{

 /* USER CODE BEGIN Error_Handler_Debug */

 /* User can add his own implementation to report the HAL error return state */

 /* USER CODE END Error_Handler_Debug */

}

#ifdef USE_FULL_ASSERT

/**

 * @brief Reports the name of the source file and the source line number

 *     where the assert_param error has occurred.

 * @param file: pointer to the source file name

 * @param line: assert_param error line source number

 * @retval None

 */

void assert_failed(uint8_t *file, uint32_t line)

{

 /* USER CODE BEGIN 6 */

 /* User can add his own implementation to report the file name and line number,

   tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

 /* USER CODE END 6 */

}

#endif /* USE_FULL_ASSERT */

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

Definitely looks like a clock issue. What bit rate did the oscilloscope show?

Check to see if RCC_HSICALIBRATION_DEFAULT gets set correctly.

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

View solution in original post

2 REPLIES 2
TDK
Guru

Definitely looks like a clock issue. What bit rate did the oscilloscope show?

Check to see if RCC_HSICALIBRATION_DEFAULT gets set correctly.

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

Really Thank you so much. It's solved at once. :D

I divided  RCC_HSICALIBRATION_DEFAULT as '2'